i915_drv.h 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758
  1. /* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
  2. */
  3. /*
  4. *
  5. * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  6. * All Rights Reserved.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the
  10. * "Software"), to deal in the Software without restriction, including
  11. * without limitation the rights to use, copy, modify, merge, publish,
  12. * distribute, sub license, and/or sell copies of the Software, and to
  13. * permit persons to whom the Software is furnished to do so, subject to
  14. * the following conditions:
  15. *
  16. * The above copyright notice and this permission notice (including the
  17. * next paragraph) shall be included in all copies or substantial portions
  18. * of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  23. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  24. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. *
  28. */
  29. #ifndef _I915_DRV_H_
  30. #define _I915_DRV_H_
  31. #include <uapi/drm/i915_drm.h>
  32. #include "i915_reg.h"
  33. #include "intel_bios.h"
  34. #include "intel_ringbuffer.h"
  35. #include "i915_gem_gtt.h"
  36. #include <linux/io-mapping.h>
  37. #include <linux/i2c.h>
  38. #include <linux/i2c-algo-bit.h>
  39. #include <drm/intel-gtt.h>
  40. #include <linux/backlight.h>
  41. #include <linux/hashtable.h>
  42. #include <linux/intel-iommu.h>
  43. #include <linux/kref.h>
  44. #include <linux/pm_qos.h>
  45. /* General customization:
  46. */
  47. #define DRIVER_AUTHOR "Tungsten Graphics, Inc."
  48. #define DRIVER_NAME "i915"
  49. #define DRIVER_DESC "Intel Graphics"
  50. #define DRIVER_DATE "20080730"
  51. enum pipe {
  52. INVALID_PIPE = -1,
  53. PIPE_A = 0,
  54. PIPE_B,
  55. PIPE_C,
  56. _PIPE_EDP,
  57. I915_MAX_PIPES = _PIPE_EDP
  58. };
  59. #define pipe_name(p) ((p) + 'A')
  60. enum transcoder {
  61. TRANSCODER_A = 0,
  62. TRANSCODER_B,
  63. TRANSCODER_C,
  64. TRANSCODER_EDP,
  65. I915_MAX_TRANSCODERS
  66. };
  67. #define transcoder_name(t) ((t) + 'A')
  68. enum plane {
  69. PLANE_A = 0,
  70. PLANE_B,
  71. PLANE_C,
  72. };
  73. #define plane_name(p) ((p) + 'A')
  74. #define sprite_name(p, s) ((p) * INTEL_INFO(dev)->num_sprites[(p)] + (s) + 'A')
  75. enum port {
  76. PORT_A = 0,
  77. PORT_B,
  78. PORT_C,
  79. PORT_D,
  80. PORT_E,
  81. I915_MAX_PORTS
  82. };
  83. #define port_name(p) ((p) + 'A')
  84. #define I915_NUM_PHYS_VLV 2
  85. enum dpio_channel {
  86. DPIO_CH0,
  87. DPIO_CH1
  88. };
  89. enum dpio_phy {
  90. DPIO_PHY0,
  91. DPIO_PHY1
  92. };
  93. enum intel_display_power_domain {
  94. POWER_DOMAIN_PIPE_A,
  95. POWER_DOMAIN_PIPE_B,
  96. POWER_DOMAIN_PIPE_C,
  97. POWER_DOMAIN_PIPE_A_PANEL_FITTER,
  98. POWER_DOMAIN_PIPE_B_PANEL_FITTER,
  99. POWER_DOMAIN_PIPE_C_PANEL_FITTER,
  100. POWER_DOMAIN_TRANSCODER_A,
  101. POWER_DOMAIN_TRANSCODER_B,
  102. POWER_DOMAIN_TRANSCODER_C,
  103. POWER_DOMAIN_TRANSCODER_EDP,
  104. POWER_DOMAIN_PORT_DDI_A_2_LANES,
  105. POWER_DOMAIN_PORT_DDI_A_4_LANES,
  106. POWER_DOMAIN_PORT_DDI_B_2_LANES,
  107. POWER_DOMAIN_PORT_DDI_B_4_LANES,
  108. POWER_DOMAIN_PORT_DDI_C_2_LANES,
  109. POWER_DOMAIN_PORT_DDI_C_4_LANES,
  110. POWER_DOMAIN_PORT_DDI_D_2_LANES,
  111. POWER_DOMAIN_PORT_DDI_D_4_LANES,
  112. POWER_DOMAIN_PORT_DSI,
  113. POWER_DOMAIN_PORT_CRT,
  114. POWER_DOMAIN_PORT_OTHER,
  115. POWER_DOMAIN_VGA,
  116. POWER_DOMAIN_AUDIO,
  117. POWER_DOMAIN_INIT,
  118. POWER_DOMAIN_NUM,
  119. };
  120. #define POWER_DOMAIN_PIPE(pipe) ((pipe) + POWER_DOMAIN_PIPE_A)
  121. #define POWER_DOMAIN_PIPE_PANEL_FITTER(pipe) \
  122. ((pipe) + POWER_DOMAIN_PIPE_A_PANEL_FITTER)
  123. #define POWER_DOMAIN_TRANSCODER(tran) \
  124. ((tran) == TRANSCODER_EDP ? POWER_DOMAIN_TRANSCODER_EDP : \
  125. (tran) + POWER_DOMAIN_TRANSCODER_A)
  126. enum hpd_pin {
  127. HPD_NONE = 0,
  128. HPD_PORT_A = HPD_NONE, /* PORT_A is internal */
  129. HPD_TV = HPD_NONE, /* TV is known to be unreliable */
  130. HPD_CRT,
  131. HPD_SDVO_B,
  132. HPD_SDVO_C,
  133. HPD_PORT_B,
  134. HPD_PORT_C,
  135. HPD_PORT_D,
  136. HPD_NUM_PINS
  137. };
  138. #define I915_GEM_GPU_DOMAINS \
  139. (I915_GEM_DOMAIN_RENDER | \
  140. I915_GEM_DOMAIN_SAMPLER | \
  141. I915_GEM_DOMAIN_COMMAND | \
  142. I915_GEM_DOMAIN_INSTRUCTION | \
  143. I915_GEM_DOMAIN_VERTEX)
  144. #define for_each_pipe(p) for ((p) = 0; (p) < INTEL_INFO(dev)->num_pipes; (p)++)
  145. #define for_each_sprite(p, s) for ((s) = 0; (s) < INTEL_INFO(dev)->num_sprites[(p)]; (s)++)
  146. #define for_each_crtc(dev, crtc) \
  147. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  148. #define for_each_intel_crtc(dev, intel_crtc) \
  149. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, base.head)
  150. #define for_each_encoder_on_crtc(dev, __crtc, intel_encoder) \
  151. list_for_each_entry((intel_encoder), &(dev)->mode_config.encoder_list, base.head) \
  152. if ((intel_encoder)->base.crtc == (__crtc))
  153. #define for_each_connector_on_encoder(dev, __encoder, intel_connector) \
  154. list_for_each_entry((intel_connector), &(dev)->mode_config.connector_list, base.head) \
  155. if ((intel_connector)->base.encoder == (__encoder))
  156. struct drm_i915_private;
  157. struct i915_mmu_object;
  158. enum intel_dpll_id {
  159. DPLL_ID_PRIVATE = -1, /* non-shared dpll in use */
  160. /* real shared dpll ids must be >= 0 */
  161. DPLL_ID_PCH_PLL_A,
  162. DPLL_ID_PCH_PLL_B,
  163. };
  164. #define I915_NUM_PLLS 2
  165. struct intel_dpll_hw_state {
  166. uint32_t dpll;
  167. uint32_t dpll_md;
  168. uint32_t fp0;
  169. uint32_t fp1;
  170. };
  171. struct intel_shared_dpll {
  172. int refcount; /* count of number of CRTCs sharing this PLL */
  173. int active; /* count of number of active CRTCs (i.e. DPMS on) */
  174. bool on; /* is the PLL actually active? Disabled during modeset */
  175. const char *name;
  176. /* should match the index in the dev_priv->shared_dplls array */
  177. enum intel_dpll_id id;
  178. struct intel_dpll_hw_state hw_state;
  179. void (*mode_set)(struct drm_i915_private *dev_priv,
  180. struct intel_shared_dpll *pll);
  181. void (*enable)(struct drm_i915_private *dev_priv,
  182. struct intel_shared_dpll *pll);
  183. void (*disable)(struct drm_i915_private *dev_priv,
  184. struct intel_shared_dpll *pll);
  185. bool (*get_hw_state)(struct drm_i915_private *dev_priv,
  186. struct intel_shared_dpll *pll,
  187. struct intel_dpll_hw_state *hw_state);
  188. };
  189. /* Used by dp and fdi links */
  190. struct intel_link_m_n {
  191. uint32_t tu;
  192. uint32_t gmch_m;
  193. uint32_t gmch_n;
  194. uint32_t link_m;
  195. uint32_t link_n;
  196. };
  197. void intel_link_compute_m_n(int bpp, int nlanes,
  198. int pixel_clock, int link_clock,
  199. struct intel_link_m_n *m_n);
  200. struct intel_ddi_plls {
  201. int spll_refcount;
  202. int wrpll1_refcount;
  203. int wrpll2_refcount;
  204. };
  205. /* Interface history:
  206. *
  207. * 1.1: Original.
  208. * 1.2: Add Power Management
  209. * 1.3: Add vblank support
  210. * 1.4: Fix cmdbuffer path, add heap destroy
  211. * 1.5: Add vblank pipe configuration
  212. * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
  213. * - Support vertical blank on secondary display pipe
  214. */
  215. #define DRIVER_MAJOR 1
  216. #define DRIVER_MINOR 6
  217. #define DRIVER_PATCHLEVEL 0
  218. #define WATCH_LISTS 0
  219. #define WATCH_GTT 0
  220. struct opregion_header;
  221. struct opregion_acpi;
  222. struct opregion_swsci;
  223. struct opregion_asle;
  224. struct intel_opregion {
  225. struct opregion_header __iomem *header;
  226. struct opregion_acpi __iomem *acpi;
  227. struct opregion_swsci __iomem *swsci;
  228. u32 swsci_gbda_sub_functions;
  229. u32 swsci_sbcb_sub_functions;
  230. struct opregion_asle __iomem *asle;
  231. void __iomem *vbt;
  232. u32 __iomem *lid_state;
  233. struct work_struct asle_work;
  234. };
  235. #define OPREGION_SIZE (8*1024)
  236. struct intel_overlay;
  237. struct intel_overlay_error_state;
  238. struct drm_i915_master_private {
  239. drm_local_map_t *sarea;
  240. struct _drm_i915_sarea *sarea_priv;
  241. };
  242. #define I915_FENCE_REG_NONE -1
  243. #define I915_MAX_NUM_FENCES 32
  244. /* 32 fences + sign bit for FENCE_REG_NONE */
  245. #define I915_MAX_NUM_FENCE_BITS 6
  246. struct drm_i915_fence_reg {
  247. struct list_head lru_list;
  248. struct drm_i915_gem_object *obj;
  249. int pin_count;
  250. };
  251. struct sdvo_device_mapping {
  252. u8 initialized;
  253. u8 dvo_port;
  254. u8 slave_addr;
  255. u8 dvo_wiring;
  256. u8 i2c_pin;
  257. u8 ddc_pin;
  258. };
  259. struct intel_display_error_state;
  260. struct drm_i915_error_state {
  261. struct kref ref;
  262. struct timeval time;
  263. char error_msg[128];
  264. u32 reset_count;
  265. u32 suspend_count;
  266. /* Generic register state */
  267. u32 eir;
  268. u32 pgtbl_er;
  269. u32 ier;
  270. u32 ccid;
  271. u32 derrmr;
  272. u32 forcewake;
  273. u32 error; /* gen6+ */
  274. u32 err_int; /* gen7 */
  275. u32 done_reg;
  276. u32 gac_eco;
  277. u32 gam_ecochk;
  278. u32 gab_ctl;
  279. u32 gfx_mode;
  280. u32 extra_instdone[I915_NUM_INSTDONE_REG];
  281. u64 fence[I915_MAX_NUM_FENCES];
  282. struct intel_overlay_error_state *overlay;
  283. struct intel_display_error_state *display;
  284. struct drm_i915_error_ring {
  285. bool valid;
  286. /* Software tracked state */
  287. bool waiting;
  288. int hangcheck_score;
  289. enum intel_ring_hangcheck_action hangcheck_action;
  290. int num_requests;
  291. /* our own tracking of ring head and tail */
  292. u32 cpu_ring_head;
  293. u32 cpu_ring_tail;
  294. u32 semaphore_seqno[I915_NUM_RINGS - 1];
  295. /* Register state */
  296. u32 tail;
  297. u32 head;
  298. u32 ctl;
  299. u32 hws;
  300. u32 ipeir;
  301. u32 ipehr;
  302. u32 instdone;
  303. u32 bbstate;
  304. u32 instpm;
  305. u32 instps;
  306. u32 seqno;
  307. u64 bbaddr;
  308. u64 acthd;
  309. u32 fault_reg;
  310. u64 faddr;
  311. u32 rc_psmi; /* sleep state */
  312. u32 semaphore_mboxes[I915_NUM_RINGS - 1];
  313. struct drm_i915_error_object {
  314. int page_count;
  315. u32 gtt_offset;
  316. u32 *pages[0];
  317. } *ringbuffer, *batchbuffer, *wa_batchbuffer, *ctx, *hws_page;
  318. struct drm_i915_error_request {
  319. long jiffies;
  320. u32 seqno;
  321. u32 tail;
  322. } *requests;
  323. struct {
  324. u32 gfx_mode;
  325. union {
  326. u64 pdp[4];
  327. u32 pp_dir_base;
  328. };
  329. } vm_info;
  330. pid_t pid;
  331. char comm[TASK_COMM_LEN];
  332. } ring[I915_NUM_RINGS];
  333. struct drm_i915_error_buffer {
  334. u32 size;
  335. u32 name;
  336. u32 rseqno, wseqno;
  337. u32 gtt_offset;
  338. u32 read_domains;
  339. u32 write_domain;
  340. s32 fence_reg:I915_MAX_NUM_FENCE_BITS;
  341. s32 pinned:2;
  342. u32 tiling:2;
  343. u32 dirty:1;
  344. u32 purgeable:1;
  345. u32 userptr:1;
  346. s32 ring:4;
  347. u32 cache_level:3;
  348. } **active_bo, **pinned_bo;
  349. u32 *active_bo_count, *pinned_bo_count;
  350. };
  351. struct intel_connector;
  352. struct intel_crtc_config;
  353. struct intel_plane_config;
  354. struct intel_crtc;
  355. struct intel_limit;
  356. struct dpll;
  357. struct drm_i915_display_funcs {
  358. bool (*fbc_enabled)(struct drm_device *dev);
  359. void (*enable_fbc)(struct drm_crtc *crtc);
  360. void (*disable_fbc)(struct drm_device *dev);
  361. int (*get_display_clock_speed)(struct drm_device *dev);
  362. int (*get_fifo_size)(struct drm_device *dev, int plane);
  363. /**
  364. * find_dpll() - Find the best values for the PLL
  365. * @limit: limits for the PLL
  366. * @crtc: current CRTC
  367. * @target: target frequency in kHz
  368. * @refclk: reference clock frequency in kHz
  369. * @match_clock: if provided, @best_clock P divider must
  370. * match the P divider from @match_clock
  371. * used for LVDS downclocking
  372. * @best_clock: best PLL values found
  373. *
  374. * Returns true on success, false on failure.
  375. */
  376. bool (*find_dpll)(const struct intel_limit *limit,
  377. struct drm_crtc *crtc,
  378. int target, int refclk,
  379. struct dpll *match_clock,
  380. struct dpll *best_clock);
  381. void (*update_wm)(struct drm_crtc *crtc);
  382. void (*update_sprite_wm)(struct drm_plane *plane,
  383. struct drm_crtc *crtc,
  384. uint32_t sprite_width, int pixel_size,
  385. bool enable, bool scaled);
  386. void (*modeset_global_resources)(struct drm_device *dev);
  387. /* Returns the active state of the crtc, and if the crtc is active,
  388. * fills out the pipe-config with the hw state. */
  389. bool (*get_pipe_config)(struct intel_crtc *,
  390. struct intel_crtc_config *);
  391. void (*get_plane_config)(struct intel_crtc *,
  392. struct intel_plane_config *);
  393. int (*crtc_mode_set)(struct drm_crtc *crtc,
  394. int x, int y,
  395. struct drm_framebuffer *old_fb);
  396. void (*crtc_enable)(struct drm_crtc *crtc);
  397. void (*crtc_disable)(struct drm_crtc *crtc);
  398. void (*off)(struct drm_crtc *crtc);
  399. void (*write_eld)(struct drm_connector *connector,
  400. struct drm_crtc *crtc,
  401. struct drm_display_mode *mode);
  402. void (*fdi_link_train)(struct drm_crtc *crtc);
  403. void (*init_clock_gating)(struct drm_device *dev);
  404. int (*queue_flip)(struct drm_device *dev, struct drm_crtc *crtc,
  405. struct drm_framebuffer *fb,
  406. struct drm_i915_gem_object *obj,
  407. struct intel_engine_cs *ring,
  408. uint32_t flags);
  409. void (*update_primary_plane)(struct drm_crtc *crtc,
  410. struct drm_framebuffer *fb,
  411. int x, int y);
  412. void (*hpd_irq_setup)(struct drm_device *dev);
  413. /* clock updates for mode set */
  414. /* cursor updates */
  415. /* render clock increase/decrease */
  416. /* display clock increase/decrease */
  417. /* pll clock increase/decrease */
  418. int (*setup_backlight)(struct intel_connector *connector);
  419. uint32_t (*get_backlight)(struct intel_connector *connector);
  420. void (*set_backlight)(struct intel_connector *connector,
  421. uint32_t level);
  422. void (*disable_backlight)(struct intel_connector *connector);
  423. void (*enable_backlight)(struct intel_connector *connector);
  424. };
  425. struct intel_uncore_funcs {
  426. void (*force_wake_get)(struct drm_i915_private *dev_priv,
  427. int fw_engine);
  428. void (*force_wake_put)(struct drm_i915_private *dev_priv,
  429. int fw_engine);
  430. uint8_t (*mmio_readb)(struct drm_i915_private *dev_priv, off_t offset, bool trace);
  431. uint16_t (*mmio_readw)(struct drm_i915_private *dev_priv, off_t offset, bool trace);
  432. uint32_t (*mmio_readl)(struct drm_i915_private *dev_priv, off_t offset, bool trace);
  433. uint64_t (*mmio_readq)(struct drm_i915_private *dev_priv, off_t offset, bool trace);
  434. void (*mmio_writeb)(struct drm_i915_private *dev_priv, off_t offset,
  435. uint8_t val, bool trace);
  436. void (*mmio_writew)(struct drm_i915_private *dev_priv, off_t offset,
  437. uint16_t val, bool trace);
  438. void (*mmio_writel)(struct drm_i915_private *dev_priv, off_t offset,
  439. uint32_t val, bool trace);
  440. void (*mmio_writeq)(struct drm_i915_private *dev_priv, off_t offset,
  441. uint64_t val, bool trace);
  442. };
  443. struct intel_uncore {
  444. spinlock_t lock; /** lock is also taken in irq contexts. */
  445. struct intel_uncore_funcs funcs;
  446. unsigned fifo_count;
  447. unsigned forcewake_count;
  448. unsigned fw_rendercount;
  449. unsigned fw_mediacount;
  450. struct timer_list force_wake_timer;
  451. };
  452. #define DEV_INFO_FOR_EACH_FLAG(func, sep) \
  453. func(is_mobile) sep \
  454. func(is_i85x) sep \
  455. func(is_i915g) sep \
  456. func(is_i945gm) sep \
  457. func(is_g33) sep \
  458. func(need_gfx_hws) sep \
  459. func(is_g4x) sep \
  460. func(is_pineview) sep \
  461. func(is_broadwater) sep \
  462. func(is_crestline) sep \
  463. func(is_ivybridge) sep \
  464. func(is_valleyview) sep \
  465. func(is_haswell) sep \
  466. func(is_preliminary) sep \
  467. func(has_fbc) sep \
  468. func(has_pipe_cxsr) sep \
  469. func(has_hotplug) sep \
  470. func(cursor_needs_physical) sep \
  471. func(has_overlay) sep \
  472. func(overlay_needs_physical) sep \
  473. func(supports_tv) sep \
  474. func(has_llc) sep \
  475. func(has_ddi) sep \
  476. func(has_fpga_dbg)
  477. #define DEFINE_FLAG(name) u8 name:1
  478. #define SEP_SEMICOLON ;
  479. struct intel_device_info {
  480. u32 display_mmio_offset;
  481. u8 num_pipes:3;
  482. u8 num_sprites[I915_MAX_PIPES];
  483. u8 gen;
  484. u8 ring_mask; /* Rings supported by the HW */
  485. DEV_INFO_FOR_EACH_FLAG(DEFINE_FLAG, SEP_SEMICOLON);
  486. /* Register offsets for the various display pipes and transcoders */
  487. int pipe_offsets[I915_MAX_TRANSCODERS];
  488. int trans_offsets[I915_MAX_TRANSCODERS];
  489. int dpll_offsets[I915_MAX_PIPES];
  490. int dpll_md_offsets[I915_MAX_PIPES];
  491. int palette_offsets[I915_MAX_PIPES];
  492. int cursor_offsets[I915_MAX_PIPES];
  493. };
  494. #undef DEFINE_FLAG
  495. #undef SEP_SEMICOLON
  496. enum i915_cache_level {
  497. I915_CACHE_NONE = 0,
  498. I915_CACHE_LLC, /* also used for snoopable memory on non-LLC */
  499. I915_CACHE_L3_LLC, /* gen7+, L3 sits between the domain specifc
  500. caches, eg sampler/render caches, and the
  501. large Last-Level-Cache. LLC is coherent with
  502. the CPU, but L3 is only visible to the GPU. */
  503. I915_CACHE_WT, /* hsw:gt3e WriteThrough for scanouts */
  504. };
  505. struct i915_ctx_hang_stats {
  506. /* This context had batch pending when hang was declared */
  507. unsigned batch_pending;
  508. /* This context had batch active when hang was declared */
  509. unsigned batch_active;
  510. /* Time when this context was last blamed for a GPU reset */
  511. unsigned long guilty_ts;
  512. /* This context is banned to submit more work */
  513. bool banned;
  514. };
  515. /* This must match up with the value previously used for execbuf2.rsvd1. */
  516. #define DEFAULT_CONTEXT_ID 0
  517. struct intel_context {
  518. struct kref ref;
  519. int id;
  520. bool is_initialized;
  521. uint8_t remap_slice;
  522. struct drm_i915_file_private *file_priv;
  523. struct intel_engine_cs *last_ring;
  524. struct drm_i915_gem_object *obj;
  525. struct i915_ctx_hang_stats hang_stats;
  526. struct i915_address_space *vm;
  527. struct list_head link;
  528. };
  529. struct i915_fbc {
  530. unsigned long size;
  531. unsigned int fb_id;
  532. enum plane plane;
  533. int y;
  534. struct drm_mm_node *compressed_fb;
  535. struct drm_mm_node *compressed_llb;
  536. struct intel_fbc_work {
  537. struct delayed_work work;
  538. struct drm_crtc *crtc;
  539. struct drm_framebuffer *fb;
  540. } *fbc_work;
  541. enum no_fbc_reason {
  542. FBC_OK, /* FBC is enabled */
  543. FBC_UNSUPPORTED, /* FBC is not supported by this chipset */
  544. FBC_NO_OUTPUT, /* no outputs enabled to compress */
  545. FBC_STOLEN_TOO_SMALL, /* not enough space for buffers */
  546. FBC_UNSUPPORTED_MODE, /* interlace or doublescanned mode */
  547. FBC_MODE_TOO_LARGE, /* mode too large for compression */
  548. FBC_BAD_PLANE, /* fbc not supported on plane */
  549. FBC_NOT_TILED, /* buffer not tiled */
  550. FBC_MULTIPLE_PIPES, /* more than one pipe active */
  551. FBC_MODULE_PARAM,
  552. FBC_CHIP_DEFAULT, /* disabled by default on this chip */
  553. } no_fbc_reason;
  554. };
  555. struct i915_drrs {
  556. struct intel_connector *connector;
  557. };
  558. struct i915_psr {
  559. bool sink_support;
  560. bool source_ok;
  561. };
  562. enum intel_pch {
  563. PCH_NONE = 0, /* No PCH present */
  564. PCH_IBX, /* Ibexpeak PCH */
  565. PCH_CPT, /* Cougarpoint PCH */
  566. PCH_LPT, /* Lynxpoint PCH */
  567. PCH_NOP,
  568. };
  569. enum intel_sbi_destination {
  570. SBI_ICLK,
  571. SBI_MPHY,
  572. };
  573. #define QUIRK_PIPEA_FORCE (1<<0)
  574. #define QUIRK_LVDS_SSC_DISABLE (1<<1)
  575. #define QUIRK_INVERT_BRIGHTNESS (1<<2)
  576. #define QUIRK_BACKLIGHT_PRESENT (1<<3)
  577. struct intel_fbdev;
  578. struct intel_fbc_work;
  579. struct intel_gmbus {
  580. struct i2c_adapter adapter;
  581. u32 force_bit;
  582. u32 reg0;
  583. u32 gpio_reg;
  584. struct i2c_algo_bit_data bit_algo;
  585. struct drm_i915_private *dev_priv;
  586. };
  587. struct i915_suspend_saved_registers {
  588. u8 saveLBB;
  589. u32 saveDSPACNTR;
  590. u32 saveDSPBCNTR;
  591. u32 saveDSPARB;
  592. u32 savePIPEACONF;
  593. u32 savePIPEBCONF;
  594. u32 savePIPEASRC;
  595. u32 savePIPEBSRC;
  596. u32 saveFPA0;
  597. u32 saveFPA1;
  598. u32 saveDPLL_A;
  599. u32 saveDPLL_A_MD;
  600. u32 saveHTOTAL_A;
  601. u32 saveHBLANK_A;
  602. u32 saveHSYNC_A;
  603. u32 saveVTOTAL_A;
  604. u32 saveVBLANK_A;
  605. u32 saveVSYNC_A;
  606. u32 saveBCLRPAT_A;
  607. u32 saveTRANSACONF;
  608. u32 saveTRANS_HTOTAL_A;
  609. u32 saveTRANS_HBLANK_A;
  610. u32 saveTRANS_HSYNC_A;
  611. u32 saveTRANS_VTOTAL_A;
  612. u32 saveTRANS_VBLANK_A;
  613. u32 saveTRANS_VSYNC_A;
  614. u32 savePIPEASTAT;
  615. u32 saveDSPASTRIDE;
  616. u32 saveDSPASIZE;
  617. u32 saveDSPAPOS;
  618. u32 saveDSPAADDR;
  619. u32 saveDSPASURF;
  620. u32 saveDSPATILEOFF;
  621. u32 savePFIT_PGM_RATIOS;
  622. u32 saveBLC_HIST_CTL;
  623. u32 saveBLC_PWM_CTL;
  624. u32 saveBLC_PWM_CTL2;
  625. u32 saveBLC_HIST_CTL_B;
  626. u32 saveBLC_CPU_PWM_CTL;
  627. u32 saveBLC_CPU_PWM_CTL2;
  628. u32 saveFPB0;
  629. u32 saveFPB1;
  630. u32 saveDPLL_B;
  631. u32 saveDPLL_B_MD;
  632. u32 saveHTOTAL_B;
  633. u32 saveHBLANK_B;
  634. u32 saveHSYNC_B;
  635. u32 saveVTOTAL_B;
  636. u32 saveVBLANK_B;
  637. u32 saveVSYNC_B;
  638. u32 saveBCLRPAT_B;
  639. u32 saveTRANSBCONF;
  640. u32 saveTRANS_HTOTAL_B;
  641. u32 saveTRANS_HBLANK_B;
  642. u32 saveTRANS_HSYNC_B;
  643. u32 saveTRANS_VTOTAL_B;
  644. u32 saveTRANS_VBLANK_B;
  645. u32 saveTRANS_VSYNC_B;
  646. u32 savePIPEBSTAT;
  647. u32 saveDSPBSTRIDE;
  648. u32 saveDSPBSIZE;
  649. u32 saveDSPBPOS;
  650. u32 saveDSPBADDR;
  651. u32 saveDSPBSURF;
  652. u32 saveDSPBTILEOFF;
  653. u32 saveVGA0;
  654. u32 saveVGA1;
  655. u32 saveVGA_PD;
  656. u32 saveVGACNTRL;
  657. u32 saveADPA;
  658. u32 saveLVDS;
  659. u32 savePP_ON_DELAYS;
  660. u32 savePP_OFF_DELAYS;
  661. u32 saveDVOA;
  662. u32 saveDVOB;
  663. u32 saveDVOC;
  664. u32 savePP_ON;
  665. u32 savePP_OFF;
  666. u32 savePP_CONTROL;
  667. u32 savePP_DIVISOR;
  668. u32 savePFIT_CONTROL;
  669. u32 save_palette_a[256];
  670. u32 save_palette_b[256];
  671. u32 saveFBC_CONTROL;
  672. u32 saveIER;
  673. u32 saveIIR;
  674. u32 saveIMR;
  675. u32 saveDEIER;
  676. u32 saveDEIMR;
  677. u32 saveGTIER;
  678. u32 saveGTIMR;
  679. u32 saveFDI_RXA_IMR;
  680. u32 saveFDI_RXB_IMR;
  681. u32 saveCACHE_MODE_0;
  682. u32 saveMI_ARB_STATE;
  683. u32 saveSWF0[16];
  684. u32 saveSWF1[16];
  685. u32 saveSWF2[3];
  686. u8 saveMSR;
  687. u8 saveSR[8];
  688. u8 saveGR[25];
  689. u8 saveAR_INDEX;
  690. u8 saveAR[21];
  691. u8 saveDACMASK;
  692. u8 saveCR[37];
  693. uint64_t saveFENCE[I915_MAX_NUM_FENCES];
  694. u32 saveCURACNTR;
  695. u32 saveCURAPOS;
  696. u32 saveCURABASE;
  697. u32 saveCURBCNTR;
  698. u32 saveCURBPOS;
  699. u32 saveCURBBASE;
  700. u32 saveCURSIZE;
  701. u32 saveDP_B;
  702. u32 saveDP_C;
  703. u32 saveDP_D;
  704. u32 savePIPEA_GMCH_DATA_M;
  705. u32 savePIPEB_GMCH_DATA_M;
  706. u32 savePIPEA_GMCH_DATA_N;
  707. u32 savePIPEB_GMCH_DATA_N;
  708. u32 savePIPEA_DP_LINK_M;
  709. u32 savePIPEB_DP_LINK_M;
  710. u32 savePIPEA_DP_LINK_N;
  711. u32 savePIPEB_DP_LINK_N;
  712. u32 saveFDI_RXA_CTL;
  713. u32 saveFDI_TXA_CTL;
  714. u32 saveFDI_RXB_CTL;
  715. u32 saveFDI_TXB_CTL;
  716. u32 savePFA_CTL_1;
  717. u32 savePFB_CTL_1;
  718. u32 savePFA_WIN_SZ;
  719. u32 savePFB_WIN_SZ;
  720. u32 savePFA_WIN_POS;
  721. u32 savePFB_WIN_POS;
  722. u32 savePCH_DREF_CONTROL;
  723. u32 saveDISP_ARB_CTL;
  724. u32 savePIPEA_DATA_M1;
  725. u32 savePIPEA_DATA_N1;
  726. u32 savePIPEA_LINK_M1;
  727. u32 savePIPEA_LINK_N1;
  728. u32 savePIPEB_DATA_M1;
  729. u32 savePIPEB_DATA_N1;
  730. u32 savePIPEB_LINK_M1;
  731. u32 savePIPEB_LINK_N1;
  732. u32 saveMCHBAR_RENDER_STANDBY;
  733. u32 savePCH_PORT_HOTPLUG;
  734. };
  735. struct vlv_s0ix_state {
  736. /* GAM */
  737. u32 wr_watermark;
  738. u32 gfx_prio_ctrl;
  739. u32 arb_mode;
  740. u32 gfx_pend_tlb0;
  741. u32 gfx_pend_tlb1;
  742. u32 lra_limits[GEN7_LRA_LIMITS_REG_NUM];
  743. u32 media_max_req_count;
  744. u32 gfx_max_req_count;
  745. u32 render_hwsp;
  746. u32 ecochk;
  747. u32 bsd_hwsp;
  748. u32 blt_hwsp;
  749. u32 tlb_rd_addr;
  750. /* MBC */
  751. u32 g3dctl;
  752. u32 gsckgctl;
  753. u32 mbctl;
  754. /* GCP */
  755. u32 ucgctl1;
  756. u32 ucgctl3;
  757. u32 rcgctl1;
  758. u32 rcgctl2;
  759. u32 rstctl;
  760. u32 misccpctl;
  761. /* GPM */
  762. u32 gfxpause;
  763. u32 rpdeuhwtc;
  764. u32 rpdeuc;
  765. u32 ecobus;
  766. u32 pwrdwnupctl;
  767. u32 rp_down_timeout;
  768. u32 rp_deucsw;
  769. u32 rcubmabdtmr;
  770. u32 rcedata;
  771. u32 spare2gh;
  772. /* Display 1 CZ domain */
  773. u32 gt_imr;
  774. u32 gt_ier;
  775. u32 pm_imr;
  776. u32 pm_ier;
  777. u32 gt_scratch[GEN7_GT_SCRATCH_REG_NUM];
  778. /* GT SA CZ domain */
  779. u32 tilectl;
  780. u32 gt_fifoctl;
  781. u32 gtlc_wake_ctrl;
  782. u32 gtlc_survive;
  783. u32 pmwgicz;
  784. /* Display 2 CZ domain */
  785. u32 gu_ctl0;
  786. u32 gu_ctl1;
  787. u32 clock_gate_dis2;
  788. };
  789. struct intel_gen6_power_mgmt {
  790. /* work and pm_iir are protected by dev_priv->irq_lock */
  791. struct work_struct work;
  792. u32 pm_iir;
  793. /* Frequencies are stored in potentially platform dependent multiples.
  794. * In other words, *_freq needs to be multiplied by X to be interesting.
  795. * Soft limits are those which are used for the dynamic reclocking done
  796. * by the driver (raise frequencies under heavy loads, and lower for
  797. * lighter loads). Hard limits are those imposed by the hardware.
  798. *
  799. * A distinction is made for overclocking, which is never enabled by
  800. * default, and is considered to be above the hard limit if it's
  801. * possible at all.
  802. */
  803. u8 cur_freq; /* Current frequency (cached, may not == HW) */
  804. u8 min_freq_softlimit; /* Minimum frequency permitted by the driver */
  805. u8 max_freq_softlimit; /* Max frequency permitted by the driver */
  806. u8 max_freq; /* Maximum frequency, RP0 if not overclocking */
  807. u8 min_freq; /* AKA RPn. Minimum frequency */
  808. u8 efficient_freq; /* AKA RPe. Pre-determined balanced frequency */
  809. u8 rp1_freq; /* "less than" RP0 power/freqency */
  810. u8 rp0_freq; /* Non-overclocked max frequency. */
  811. int last_adj;
  812. enum { LOW_POWER, BETWEEN, HIGH_POWER } power;
  813. bool enabled;
  814. struct delayed_work delayed_resume_work;
  815. /*
  816. * Protects RPS/RC6 register access and PCU communication.
  817. * Must be taken after struct_mutex if nested.
  818. */
  819. struct mutex hw_lock;
  820. };
  821. /* defined intel_pm.c */
  822. extern spinlock_t mchdev_lock;
  823. struct intel_ilk_power_mgmt {
  824. u8 cur_delay;
  825. u8 min_delay;
  826. u8 max_delay;
  827. u8 fmax;
  828. u8 fstart;
  829. u64 last_count1;
  830. unsigned long last_time1;
  831. unsigned long chipset_power;
  832. u64 last_count2;
  833. struct timespec last_time2;
  834. unsigned long gfx_power;
  835. u8 corr;
  836. int c_m;
  837. int r_t;
  838. struct drm_i915_gem_object *pwrctx;
  839. struct drm_i915_gem_object *renderctx;
  840. };
  841. struct drm_i915_private;
  842. struct i915_power_well;
  843. struct i915_power_well_ops {
  844. /*
  845. * Synchronize the well's hw state to match the current sw state, for
  846. * example enable/disable it based on the current refcount. Called
  847. * during driver init and resume time, possibly after first calling
  848. * the enable/disable handlers.
  849. */
  850. void (*sync_hw)(struct drm_i915_private *dev_priv,
  851. struct i915_power_well *power_well);
  852. /*
  853. * Enable the well and resources that depend on it (for example
  854. * interrupts located on the well). Called after the 0->1 refcount
  855. * transition.
  856. */
  857. void (*enable)(struct drm_i915_private *dev_priv,
  858. struct i915_power_well *power_well);
  859. /*
  860. * Disable the well and resources that depend on it. Called after
  861. * the 1->0 refcount transition.
  862. */
  863. void (*disable)(struct drm_i915_private *dev_priv,
  864. struct i915_power_well *power_well);
  865. /* Returns the hw enabled state. */
  866. bool (*is_enabled)(struct drm_i915_private *dev_priv,
  867. struct i915_power_well *power_well);
  868. };
  869. /* Power well structure for haswell */
  870. struct i915_power_well {
  871. const char *name;
  872. bool always_on;
  873. /* power well enable/disable usage count */
  874. int count;
  875. /* cached hw enabled state */
  876. bool hw_enabled;
  877. unsigned long domains;
  878. unsigned long data;
  879. const struct i915_power_well_ops *ops;
  880. };
  881. struct i915_power_domains {
  882. /*
  883. * Power wells needed for initialization at driver init and suspend
  884. * time are on. They are kept on until after the first modeset.
  885. */
  886. bool init_power_on;
  887. bool initializing;
  888. int power_well_count;
  889. struct mutex lock;
  890. int domain_use_count[POWER_DOMAIN_NUM];
  891. struct i915_power_well *power_wells;
  892. };
  893. struct i915_dri1_state {
  894. unsigned allow_batchbuffer : 1;
  895. u32 __iomem *gfx_hws_cpu_addr;
  896. unsigned int cpp;
  897. int back_offset;
  898. int front_offset;
  899. int current_page;
  900. int page_flipping;
  901. uint32_t counter;
  902. };
  903. struct i915_ums_state {
  904. /**
  905. * Flag if the X Server, and thus DRM, is not currently in
  906. * control of the device.
  907. *
  908. * This is set between LeaveVT and EnterVT. It needs to be
  909. * replaced with a semaphore. It also needs to be
  910. * transitioned away from for kernel modesetting.
  911. */
  912. int mm_suspended;
  913. };
  914. #define MAX_L3_SLICES 2
  915. struct intel_l3_parity {
  916. u32 *remap_info[MAX_L3_SLICES];
  917. struct work_struct error_work;
  918. int which_slice;
  919. };
  920. struct i915_gem_mm {
  921. /** Memory allocator for GTT stolen memory */
  922. struct drm_mm stolen;
  923. /** List of all objects in gtt_space. Used to restore gtt
  924. * mappings on resume */
  925. struct list_head bound_list;
  926. /**
  927. * List of objects which are not bound to the GTT (thus
  928. * are idle and not used by the GPU) but still have
  929. * (presumably uncached) pages still attached.
  930. */
  931. struct list_head unbound_list;
  932. /** Usable portion of the GTT for GEM */
  933. unsigned long stolen_base; /* limited to low memory (32-bit) */
  934. /** PPGTT used for aliasing the PPGTT with the GTT */
  935. struct i915_hw_ppgtt *aliasing_ppgtt;
  936. struct notifier_block oom_notifier;
  937. struct shrinker shrinker;
  938. bool shrinker_no_lock_stealing;
  939. /** LRU list of objects with fence regs on them. */
  940. struct list_head fence_list;
  941. /**
  942. * We leave the user IRQ off as much as possible,
  943. * but this means that requests will finish and never
  944. * be retired once the system goes idle. Set a timer to
  945. * fire periodically while the ring is running. When it
  946. * fires, go retire requests.
  947. */
  948. struct delayed_work retire_work;
  949. /**
  950. * When we detect an idle GPU, we want to turn on
  951. * powersaving features. So once we see that there
  952. * are no more requests outstanding and no more
  953. * arrive within a small period of time, we fire
  954. * off the idle_work.
  955. */
  956. struct delayed_work idle_work;
  957. /**
  958. * Are we in a non-interruptible section of code like
  959. * modesetting?
  960. */
  961. bool interruptible;
  962. /**
  963. * Is the GPU currently considered idle, or busy executing userspace
  964. * requests? Whilst idle, we attempt to power down the hardware and
  965. * display clocks. In order to reduce the effect on performance, there
  966. * is a slight delay before we do so.
  967. */
  968. bool busy;
  969. /* the indicator for dispatch video commands on two BSD rings */
  970. int bsd_ring_dispatch_index;
  971. /** Bit 6 swizzling required for X tiling */
  972. uint32_t bit_6_swizzle_x;
  973. /** Bit 6 swizzling required for Y tiling */
  974. uint32_t bit_6_swizzle_y;
  975. /* accounting, useful for userland debugging */
  976. spinlock_t object_stat_lock;
  977. size_t object_memory;
  978. u32 object_count;
  979. };
  980. struct drm_i915_error_state_buf {
  981. unsigned bytes;
  982. unsigned size;
  983. int err;
  984. u8 *buf;
  985. loff_t start;
  986. loff_t pos;
  987. };
  988. struct i915_error_state_file_priv {
  989. struct drm_device *dev;
  990. struct drm_i915_error_state *error;
  991. };
  992. struct i915_gpu_error {
  993. /* For hangcheck timer */
  994. #define DRM_I915_HANGCHECK_PERIOD 1500 /* in ms */
  995. #define DRM_I915_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)
  996. /* Hang gpu twice in this window and your context gets banned */
  997. #define DRM_I915_CTX_BAN_PERIOD DIV_ROUND_UP(8*DRM_I915_HANGCHECK_PERIOD, 1000)
  998. struct timer_list hangcheck_timer;
  999. /* For reset and error_state handling. */
  1000. spinlock_t lock;
  1001. /* Protected by the above dev->gpu_error.lock. */
  1002. struct drm_i915_error_state *first_error;
  1003. struct work_struct work;
  1004. unsigned long missed_irq_rings;
  1005. /**
  1006. * State variable controlling the reset flow and count
  1007. *
  1008. * This is a counter which gets incremented when reset is triggered,
  1009. * and again when reset has been handled. So odd values (lowest bit set)
  1010. * means that reset is in progress and even values that
  1011. * (reset_counter >> 1):th reset was successfully completed.
  1012. *
  1013. * If reset is not completed succesfully, the I915_WEDGE bit is
  1014. * set meaning that hardware is terminally sour and there is no
  1015. * recovery. All waiters on the reset_queue will be woken when
  1016. * that happens.
  1017. *
  1018. * This counter is used by the wait_seqno code to notice that reset
  1019. * event happened and it needs to restart the entire ioctl (since most
  1020. * likely the seqno it waited for won't ever signal anytime soon).
  1021. *
  1022. * This is important for lock-free wait paths, where no contended lock
  1023. * naturally enforces the correct ordering between the bail-out of the
  1024. * waiter and the gpu reset work code.
  1025. */
  1026. atomic_t reset_counter;
  1027. #define I915_RESET_IN_PROGRESS_FLAG 1
  1028. #define I915_WEDGED (1 << 31)
  1029. /**
  1030. * Waitqueue to signal when the reset has completed. Used by clients
  1031. * that wait for dev_priv->mm.wedged to settle.
  1032. */
  1033. wait_queue_head_t reset_queue;
  1034. /* Userspace knobs for gpu hang simulation;
  1035. * combines both a ring mask, and extra flags
  1036. */
  1037. u32 stop_rings;
  1038. #define I915_STOP_RING_ALLOW_BAN (1 << 31)
  1039. #define I915_STOP_RING_ALLOW_WARN (1 << 30)
  1040. /* For missed irq/seqno simulation. */
  1041. unsigned int test_irq_rings;
  1042. };
  1043. enum modeset_restore {
  1044. MODESET_ON_LID_OPEN,
  1045. MODESET_DONE,
  1046. MODESET_SUSPENDED,
  1047. };
  1048. struct ddi_vbt_port_info {
  1049. uint8_t hdmi_level_shift;
  1050. uint8_t supports_dvi:1;
  1051. uint8_t supports_hdmi:1;
  1052. uint8_t supports_dp:1;
  1053. };
  1054. enum drrs_support_type {
  1055. DRRS_NOT_SUPPORTED = 0,
  1056. STATIC_DRRS_SUPPORT = 1,
  1057. SEAMLESS_DRRS_SUPPORT = 2
  1058. };
  1059. struct intel_vbt_data {
  1060. struct drm_display_mode *lfp_lvds_vbt_mode; /* if any */
  1061. struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */
  1062. /* Feature bits */
  1063. unsigned int int_tv_support:1;
  1064. unsigned int lvds_dither:1;
  1065. unsigned int lvds_vbt:1;
  1066. unsigned int int_crt_support:1;
  1067. unsigned int lvds_use_ssc:1;
  1068. unsigned int display_clock_mode:1;
  1069. unsigned int fdi_rx_polarity_inverted:1;
  1070. unsigned int has_mipi:1;
  1071. int lvds_ssc_freq;
  1072. unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */
  1073. enum drrs_support_type drrs_type;
  1074. /* eDP */
  1075. int edp_rate;
  1076. int edp_lanes;
  1077. int edp_preemphasis;
  1078. int edp_vswing;
  1079. bool edp_initialized;
  1080. bool edp_support;
  1081. int edp_bpp;
  1082. struct edp_power_seq edp_pps;
  1083. struct {
  1084. u16 pwm_freq_hz;
  1085. bool present;
  1086. bool active_low_pwm;
  1087. } backlight;
  1088. /* MIPI DSI */
  1089. struct {
  1090. u16 port;
  1091. u16 panel_id;
  1092. struct mipi_config *config;
  1093. struct mipi_pps_data *pps;
  1094. u8 seq_version;
  1095. u32 size;
  1096. u8 *data;
  1097. u8 *sequence[MIPI_SEQ_MAX];
  1098. } dsi;
  1099. int crt_ddc_pin;
  1100. int child_dev_num;
  1101. union child_device_config *child_dev;
  1102. struct ddi_vbt_port_info ddi_port_info[I915_MAX_PORTS];
  1103. };
  1104. enum intel_ddb_partitioning {
  1105. INTEL_DDB_PART_1_2,
  1106. INTEL_DDB_PART_5_6, /* IVB+ */
  1107. };
  1108. struct intel_wm_level {
  1109. bool enable;
  1110. uint32_t pri_val;
  1111. uint32_t spr_val;
  1112. uint32_t cur_val;
  1113. uint32_t fbc_val;
  1114. };
  1115. struct ilk_wm_values {
  1116. uint32_t wm_pipe[3];
  1117. uint32_t wm_lp[3];
  1118. uint32_t wm_lp_spr[3];
  1119. uint32_t wm_linetime[3];
  1120. bool enable_fbc_wm;
  1121. enum intel_ddb_partitioning partitioning;
  1122. };
  1123. /*
  1124. * This struct helps tracking the state needed for runtime PM, which puts the
  1125. * device in PCI D3 state. Notice that when this happens, nothing on the
  1126. * graphics device works, even register access, so we don't get interrupts nor
  1127. * anything else.
  1128. *
  1129. * Every piece of our code that needs to actually touch the hardware needs to
  1130. * either call intel_runtime_pm_get or call intel_display_power_get with the
  1131. * appropriate power domain.
  1132. *
  1133. * Our driver uses the autosuspend delay feature, which means we'll only really
  1134. * suspend if we stay with zero refcount for a certain amount of time. The
  1135. * default value is currently very conservative (see intel_init_runtime_pm), but
  1136. * it can be changed with the standard runtime PM files from sysfs.
  1137. *
  1138. * The irqs_disabled variable becomes true exactly after we disable the IRQs and
  1139. * goes back to false exactly before we reenable the IRQs. We use this variable
  1140. * to check if someone is trying to enable/disable IRQs while they're supposed
  1141. * to be disabled. This shouldn't happen and we'll print some error messages in
  1142. * case it happens.
  1143. *
  1144. * For more, read the Documentation/power/runtime_pm.txt.
  1145. */
  1146. struct i915_runtime_pm {
  1147. bool suspended;
  1148. bool irqs_disabled;
  1149. };
  1150. enum intel_pipe_crc_source {
  1151. INTEL_PIPE_CRC_SOURCE_NONE,
  1152. INTEL_PIPE_CRC_SOURCE_PLANE1,
  1153. INTEL_PIPE_CRC_SOURCE_PLANE2,
  1154. INTEL_PIPE_CRC_SOURCE_PF,
  1155. INTEL_PIPE_CRC_SOURCE_PIPE,
  1156. /* TV/DP on pre-gen5/vlv can't use the pipe source. */
  1157. INTEL_PIPE_CRC_SOURCE_TV,
  1158. INTEL_PIPE_CRC_SOURCE_DP_B,
  1159. INTEL_PIPE_CRC_SOURCE_DP_C,
  1160. INTEL_PIPE_CRC_SOURCE_DP_D,
  1161. INTEL_PIPE_CRC_SOURCE_AUTO,
  1162. INTEL_PIPE_CRC_SOURCE_MAX,
  1163. };
  1164. struct intel_pipe_crc_entry {
  1165. uint32_t frame;
  1166. uint32_t crc[5];
  1167. };
  1168. #define INTEL_PIPE_CRC_ENTRIES_NR 128
  1169. struct intel_pipe_crc {
  1170. spinlock_t lock;
  1171. bool opened; /* exclusive access to the result file */
  1172. struct intel_pipe_crc_entry *entries;
  1173. enum intel_pipe_crc_source source;
  1174. int head, tail;
  1175. wait_queue_head_t wq;
  1176. };
  1177. struct drm_i915_private {
  1178. struct drm_device *dev;
  1179. struct kmem_cache *slab;
  1180. const struct intel_device_info info;
  1181. int relative_constants_mode;
  1182. void __iomem *regs;
  1183. struct intel_uncore uncore;
  1184. struct intel_gmbus gmbus[GMBUS_NUM_PORTS];
  1185. /** gmbus_mutex protects against concurrent usage of the single hw gmbus
  1186. * controller on different i2c buses. */
  1187. struct mutex gmbus_mutex;
  1188. /**
  1189. * Base address of the gmbus and gpio block.
  1190. */
  1191. uint32_t gpio_mmio_base;
  1192. /* MMIO base address for MIPI regs */
  1193. uint32_t mipi_mmio_base;
  1194. wait_queue_head_t gmbus_wait_queue;
  1195. struct pci_dev *bridge_dev;
  1196. struct intel_engine_cs ring[I915_NUM_RINGS];
  1197. uint32_t last_seqno, next_seqno;
  1198. drm_dma_handle_t *status_page_dmah;
  1199. struct resource mch_res;
  1200. /* protects the irq masks */
  1201. spinlock_t irq_lock;
  1202. bool display_irqs_enabled;
  1203. /* To control wakeup latency, e.g. for irq-driven dp aux transfers. */
  1204. struct pm_qos_request pm_qos;
  1205. /* DPIO indirect register protection */
  1206. struct mutex dpio_lock;
  1207. /** Cached value of IMR to avoid reads in updating the bitfield */
  1208. union {
  1209. u32 irq_mask;
  1210. u32 de_irq_mask[I915_MAX_PIPES];
  1211. };
  1212. u32 gt_irq_mask;
  1213. u32 pm_irq_mask;
  1214. u32 pm_rps_events;
  1215. u32 pipestat_irq_mask[I915_MAX_PIPES];
  1216. struct work_struct hotplug_work;
  1217. bool enable_hotplug_processing;
  1218. struct {
  1219. unsigned long hpd_last_jiffies;
  1220. int hpd_cnt;
  1221. enum {
  1222. HPD_ENABLED = 0,
  1223. HPD_DISABLED = 1,
  1224. HPD_MARK_DISABLED = 2
  1225. } hpd_mark;
  1226. } hpd_stats[HPD_NUM_PINS];
  1227. u32 hpd_event_bits;
  1228. struct timer_list hotplug_reenable_timer;
  1229. struct i915_fbc fbc;
  1230. struct i915_drrs drrs;
  1231. struct intel_opregion opregion;
  1232. struct intel_vbt_data vbt;
  1233. /* overlay */
  1234. struct intel_overlay *overlay;
  1235. /* backlight registers and fields in struct intel_panel */
  1236. spinlock_t backlight_lock;
  1237. /* LVDS info */
  1238. bool no_aux_handshake;
  1239. struct drm_i915_fence_reg fence_regs[I915_MAX_NUM_FENCES]; /* assume 965 */
  1240. int fence_reg_start; /* 4 if userland hasn't ioctl'd us yet */
  1241. int num_fence_regs; /* 8 on pre-965, 16 otherwise */
  1242. unsigned int fsb_freq, mem_freq, is_ddr3;
  1243. unsigned int vlv_cdclk_freq;
  1244. /**
  1245. * wq - Driver workqueue for GEM.
  1246. *
  1247. * NOTE: Work items scheduled here are not allowed to grab any modeset
  1248. * locks, for otherwise the flushing done in the pageflip code will
  1249. * result in deadlocks.
  1250. */
  1251. struct workqueue_struct *wq;
  1252. /* Display functions */
  1253. struct drm_i915_display_funcs display;
  1254. /* PCH chipset type */
  1255. enum intel_pch pch_type;
  1256. unsigned short pch_id;
  1257. unsigned long quirks;
  1258. enum modeset_restore modeset_restore;
  1259. struct mutex modeset_restore_lock;
  1260. struct list_head vm_list; /* Global list of all address spaces */
  1261. struct i915_gtt gtt; /* VM representing the global address space */
  1262. struct i915_gem_mm mm;
  1263. #if defined(CONFIG_MMU_NOTIFIER)
  1264. DECLARE_HASHTABLE(mmu_notifiers, 7);
  1265. #endif
  1266. /* Kernel Modesetting */
  1267. struct sdvo_device_mapping sdvo_mappings[2];
  1268. struct drm_crtc *plane_to_crtc_mapping[I915_MAX_PIPES];
  1269. struct drm_crtc *pipe_to_crtc_mapping[I915_MAX_PIPES];
  1270. wait_queue_head_t pending_flip_queue;
  1271. #ifdef CONFIG_DEBUG_FS
  1272. struct intel_pipe_crc pipe_crc[I915_MAX_PIPES];
  1273. #endif
  1274. int num_shared_dpll;
  1275. struct intel_shared_dpll shared_dplls[I915_NUM_PLLS];
  1276. struct intel_ddi_plls ddi_plls;
  1277. int dpio_phy_iosf_port[I915_NUM_PHYS_VLV];
  1278. /* Reclocking support */
  1279. bool render_reclock_avail;
  1280. bool lvds_downclock_avail;
  1281. /* indicates the reduced downclock for LVDS*/
  1282. int lvds_downclock;
  1283. u16 orig_clock;
  1284. bool mchbar_need_disable;
  1285. struct intel_l3_parity l3_parity;
  1286. /* Cannot be determined by PCIID. You must always read a register. */
  1287. size_t ellc_size;
  1288. /* gen6+ rps state */
  1289. struct intel_gen6_power_mgmt rps;
  1290. /* ilk-only ips/rps state. Everything in here is protected by the global
  1291. * mchdev_lock in intel_pm.c */
  1292. struct intel_ilk_power_mgmt ips;
  1293. struct i915_power_domains power_domains;
  1294. struct i915_psr psr;
  1295. struct i915_gpu_error gpu_error;
  1296. struct drm_i915_gem_object *vlv_pctx;
  1297. #ifdef CONFIG_DRM_I915_FBDEV
  1298. /* list of fbdev register on this device */
  1299. struct intel_fbdev *fbdev;
  1300. #endif
  1301. /*
  1302. * The console may be contended at resume, but we don't
  1303. * want it to block on it.
  1304. */
  1305. struct work_struct console_resume_work;
  1306. struct drm_property *broadcast_rgb_property;
  1307. struct drm_property *force_audio_property;
  1308. uint32_t hw_context_size;
  1309. struct list_head context_list;
  1310. u32 fdi_rx_config;
  1311. u32 suspend_count;
  1312. struct i915_suspend_saved_registers regfile;
  1313. struct vlv_s0ix_state vlv_s0ix_state;
  1314. struct {
  1315. /*
  1316. * Raw watermark latency values:
  1317. * in 0.1us units for WM0,
  1318. * in 0.5us units for WM1+.
  1319. */
  1320. /* primary */
  1321. uint16_t pri_latency[5];
  1322. /* sprite */
  1323. uint16_t spr_latency[5];
  1324. /* cursor */
  1325. uint16_t cur_latency[5];
  1326. /* current hardware state */
  1327. struct ilk_wm_values hw;
  1328. } wm;
  1329. struct i915_runtime_pm pm;
  1330. /* Old dri1 support infrastructure, beware the dragons ya fools entering
  1331. * here! */
  1332. struct i915_dri1_state dri1;
  1333. /* Old ums support infrastructure, same warning applies. */
  1334. struct i915_ums_state ums;
  1335. /*
  1336. * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
  1337. * will be rejected. Instead look for a better place.
  1338. */
  1339. };
  1340. static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
  1341. {
  1342. return dev->dev_private;
  1343. }
  1344. /* Iterate over initialised rings */
  1345. #define for_each_ring(ring__, dev_priv__, i__) \
  1346. for ((i__) = 0; (i__) < I915_NUM_RINGS; (i__)++) \
  1347. if (((ring__) = &(dev_priv__)->ring[(i__)]), intel_ring_initialized((ring__)))
  1348. enum hdmi_force_audio {
  1349. HDMI_AUDIO_OFF_DVI = -2, /* no aux data for HDMI-DVI converter */
  1350. HDMI_AUDIO_OFF, /* force turn off HDMI audio */
  1351. HDMI_AUDIO_AUTO, /* trust EDID */
  1352. HDMI_AUDIO_ON, /* force turn on HDMI audio */
  1353. };
  1354. #define I915_GTT_OFFSET_NONE ((u32)-1)
  1355. struct drm_i915_gem_object_ops {
  1356. /* Interface between the GEM object and its backing storage.
  1357. * get_pages() is called once prior to the use of the associated set
  1358. * of pages before to binding them into the GTT, and put_pages() is
  1359. * called after we no longer need them. As we expect there to be
  1360. * associated cost with migrating pages between the backing storage
  1361. * and making them available for the GPU (e.g. clflush), we may hold
  1362. * onto the pages after they are no longer referenced by the GPU
  1363. * in case they may be used again shortly (for example migrating the
  1364. * pages to a different memory domain within the GTT). put_pages()
  1365. * will therefore most likely be called when the object itself is
  1366. * being released or under memory pressure (where we attempt to
  1367. * reap pages for the shrinker).
  1368. */
  1369. int (*get_pages)(struct drm_i915_gem_object *);
  1370. void (*put_pages)(struct drm_i915_gem_object *);
  1371. int (*dmabuf_export)(struct drm_i915_gem_object *);
  1372. void (*release)(struct drm_i915_gem_object *);
  1373. };
  1374. struct drm_i915_gem_object {
  1375. struct drm_gem_object base;
  1376. const struct drm_i915_gem_object_ops *ops;
  1377. /** List of VMAs backed by this object */
  1378. struct list_head vma_list;
  1379. /** Stolen memory for this object, instead of being backed by shmem. */
  1380. struct drm_mm_node *stolen;
  1381. struct list_head global_list;
  1382. struct list_head ring_list;
  1383. /** Used in execbuf to temporarily hold a ref */
  1384. struct list_head obj_exec_link;
  1385. /**
  1386. * This is set if the object is on the active lists (has pending
  1387. * rendering and so a non-zero seqno), and is not set if it i s on
  1388. * inactive (ready to be unbound) list.
  1389. */
  1390. unsigned int active:1;
  1391. /**
  1392. * This is set if the object has been written to since last bound
  1393. * to the GTT
  1394. */
  1395. unsigned int dirty:1;
  1396. /**
  1397. * Fence register bits (if any) for this object. Will be set
  1398. * as needed when mapped into the GTT.
  1399. * Protected by dev->struct_mutex.
  1400. */
  1401. signed int fence_reg:I915_MAX_NUM_FENCE_BITS;
  1402. /**
  1403. * Advice: are the backing pages purgeable?
  1404. */
  1405. unsigned int madv:2;
  1406. /**
  1407. * Current tiling mode for the object.
  1408. */
  1409. unsigned int tiling_mode:2;
  1410. /**
  1411. * Whether the tiling parameters for the currently associated fence
  1412. * register have changed. Note that for the purposes of tracking
  1413. * tiling changes we also treat the unfenced register, the register
  1414. * slot that the object occupies whilst it executes a fenced
  1415. * command (such as BLT on gen2/3), as a "fence".
  1416. */
  1417. unsigned int fence_dirty:1;
  1418. /**
  1419. * Is the object at the current location in the gtt mappable and
  1420. * fenceable? Used to avoid costly recalculations.
  1421. */
  1422. unsigned int map_and_fenceable:1;
  1423. /**
  1424. * Whether the current gtt mapping needs to be mappable (and isn't just
  1425. * mappable by accident). Track pin and fault separate for a more
  1426. * accurate mappable working set.
  1427. */
  1428. unsigned int fault_mappable:1;
  1429. unsigned int pin_mappable:1;
  1430. unsigned int pin_display:1;
  1431. /*
  1432. * Is the GPU currently using a fence to access this buffer,
  1433. */
  1434. unsigned int pending_fenced_gpu_access:1;
  1435. unsigned int fenced_gpu_access:1;
  1436. unsigned int cache_level:3;
  1437. unsigned int has_aliasing_ppgtt_mapping:1;
  1438. unsigned int has_global_gtt_mapping:1;
  1439. unsigned int has_dma_mapping:1;
  1440. struct sg_table *pages;
  1441. int pages_pin_count;
  1442. /* prime dma-buf support */
  1443. void *dma_buf_vmapping;
  1444. int vmapping_count;
  1445. struct intel_engine_cs *ring;
  1446. /** Breadcrumb of last rendering to the buffer. */
  1447. uint32_t last_read_seqno;
  1448. uint32_t last_write_seqno;
  1449. /** Breadcrumb of last fenced GPU access to the buffer. */
  1450. uint32_t last_fenced_seqno;
  1451. /** Current tiling stride for the object, if it's tiled. */
  1452. uint32_t stride;
  1453. /** References from framebuffers, locks out tiling changes. */
  1454. unsigned long framebuffer_references;
  1455. /** Record of address bit 17 of each page at last unbind. */
  1456. unsigned long *bit_17;
  1457. /** User space pin count and filp owning the pin */
  1458. unsigned long user_pin_count;
  1459. struct drm_file *pin_filp;
  1460. /** for phy allocated objects */
  1461. drm_dma_handle_t *phys_handle;
  1462. union {
  1463. struct i915_gem_userptr {
  1464. uintptr_t ptr;
  1465. unsigned read_only :1;
  1466. unsigned workers :4;
  1467. #define I915_GEM_USERPTR_MAX_WORKERS 15
  1468. struct mm_struct *mm;
  1469. struct i915_mmu_object *mn;
  1470. struct work_struct *work;
  1471. } userptr;
  1472. };
  1473. };
  1474. #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
  1475. /**
  1476. * Request queue structure.
  1477. *
  1478. * The request queue allows us to note sequence numbers that have been emitted
  1479. * and may be associated with active buffers to be retired.
  1480. *
  1481. * By keeping this list, we can avoid having to do questionable
  1482. * sequence-number comparisons on buffer last_rendering_seqnos, and associate
  1483. * an emission time with seqnos for tracking how far ahead of the GPU we are.
  1484. */
  1485. struct drm_i915_gem_request {
  1486. /** On Which ring this request was generated */
  1487. struct intel_engine_cs *ring;
  1488. /** GEM sequence number associated with this request. */
  1489. uint32_t seqno;
  1490. /** Position in the ringbuffer of the start of the request */
  1491. u32 head;
  1492. /** Position in the ringbuffer of the end of the request */
  1493. u32 tail;
  1494. /** Context related to this request */
  1495. struct intel_context *ctx;
  1496. /** Batch buffer related to this request if any */
  1497. struct drm_i915_gem_object *batch_obj;
  1498. /** Time at which this request was emitted, in jiffies. */
  1499. unsigned long emitted_jiffies;
  1500. /** global list entry for this request */
  1501. struct list_head list;
  1502. struct drm_i915_file_private *file_priv;
  1503. /** file_priv list entry for this request */
  1504. struct list_head client_list;
  1505. };
  1506. struct drm_i915_file_private {
  1507. struct drm_i915_private *dev_priv;
  1508. struct drm_file *file;
  1509. struct {
  1510. spinlock_t lock;
  1511. struct list_head request_list;
  1512. struct delayed_work idle_work;
  1513. } mm;
  1514. struct idr context_idr;
  1515. atomic_t rps_wait_boost;
  1516. struct intel_engine_cs *bsd_ring;
  1517. };
  1518. /*
  1519. * A command that requires special handling by the command parser.
  1520. */
  1521. struct drm_i915_cmd_descriptor {
  1522. /*
  1523. * Flags describing how the command parser processes the command.
  1524. *
  1525. * CMD_DESC_FIXED: The command has a fixed length if this is set,
  1526. * a length mask if not set
  1527. * CMD_DESC_SKIP: The command is allowed but does not follow the
  1528. * standard length encoding for the opcode range in
  1529. * which it falls
  1530. * CMD_DESC_REJECT: The command is never allowed
  1531. * CMD_DESC_REGISTER: The command should be checked against the
  1532. * register whitelist for the appropriate ring
  1533. * CMD_DESC_MASTER: The command is allowed if the submitting process
  1534. * is the DRM master
  1535. */
  1536. u32 flags;
  1537. #define CMD_DESC_FIXED (1<<0)
  1538. #define CMD_DESC_SKIP (1<<1)
  1539. #define CMD_DESC_REJECT (1<<2)
  1540. #define CMD_DESC_REGISTER (1<<3)
  1541. #define CMD_DESC_BITMASK (1<<4)
  1542. #define CMD_DESC_MASTER (1<<5)
  1543. /*
  1544. * The command's unique identification bits and the bitmask to get them.
  1545. * This isn't strictly the opcode field as defined in the spec and may
  1546. * also include type, subtype, and/or subop fields.
  1547. */
  1548. struct {
  1549. u32 value;
  1550. u32 mask;
  1551. } cmd;
  1552. /*
  1553. * The command's length. The command is either fixed length (i.e. does
  1554. * not include a length field) or has a length field mask. The flag
  1555. * CMD_DESC_FIXED indicates a fixed length. Otherwise, the command has
  1556. * a length mask. All command entries in a command table must include
  1557. * length information.
  1558. */
  1559. union {
  1560. u32 fixed;
  1561. u32 mask;
  1562. } length;
  1563. /*
  1564. * Describes where to find a register address in the command to check
  1565. * against the ring's register whitelist. Only valid if flags has the
  1566. * CMD_DESC_REGISTER bit set.
  1567. */
  1568. struct {
  1569. u32 offset;
  1570. u32 mask;
  1571. } reg;
  1572. #define MAX_CMD_DESC_BITMASKS 3
  1573. /*
  1574. * Describes command checks where a particular dword is masked and
  1575. * compared against an expected value. If the command does not match
  1576. * the expected value, the parser rejects it. Only valid if flags has
  1577. * the CMD_DESC_BITMASK bit set. Only entries where mask is non-zero
  1578. * are valid.
  1579. *
  1580. * If the check specifies a non-zero condition_mask then the parser
  1581. * only performs the check when the bits specified by condition_mask
  1582. * are non-zero.
  1583. */
  1584. struct {
  1585. u32 offset;
  1586. u32 mask;
  1587. u32 expected;
  1588. u32 condition_offset;
  1589. u32 condition_mask;
  1590. } bits[MAX_CMD_DESC_BITMASKS];
  1591. };
  1592. /*
  1593. * A table of commands requiring special handling by the command parser.
  1594. *
  1595. * Each ring has an array of tables. Each table consists of an array of command
  1596. * descriptors, which must be sorted with command opcodes in ascending order.
  1597. */
  1598. struct drm_i915_cmd_table {
  1599. const struct drm_i915_cmd_descriptor *table;
  1600. int count;
  1601. };
  1602. #define INTEL_INFO(dev) (&to_i915(dev)->info)
  1603. #define IS_I830(dev) ((dev)->pdev->device == 0x3577)
  1604. #define IS_845G(dev) ((dev)->pdev->device == 0x2562)
  1605. #define IS_I85X(dev) (INTEL_INFO(dev)->is_i85x)
  1606. #define IS_I865G(dev) ((dev)->pdev->device == 0x2572)
  1607. #define IS_I915G(dev) (INTEL_INFO(dev)->is_i915g)
  1608. #define IS_I915GM(dev) ((dev)->pdev->device == 0x2592)
  1609. #define IS_I945G(dev) ((dev)->pdev->device == 0x2772)
  1610. #define IS_I945GM(dev) (INTEL_INFO(dev)->is_i945gm)
  1611. #define IS_BROADWATER(dev) (INTEL_INFO(dev)->is_broadwater)
  1612. #define IS_CRESTLINE(dev) (INTEL_INFO(dev)->is_crestline)
  1613. #define IS_GM45(dev) ((dev)->pdev->device == 0x2A42)
  1614. #define IS_G4X(dev) (INTEL_INFO(dev)->is_g4x)
  1615. #define IS_PINEVIEW_G(dev) ((dev)->pdev->device == 0xa001)
  1616. #define IS_PINEVIEW_M(dev) ((dev)->pdev->device == 0xa011)
  1617. #define IS_PINEVIEW(dev) (INTEL_INFO(dev)->is_pineview)
  1618. #define IS_G33(dev) (INTEL_INFO(dev)->is_g33)
  1619. #define IS_IRONLAKE_M(dev) ((dev)->pdev->device == 0x0046)
  1620. #define IS_IVYBRIDGE(dev) (INTEL_INFO(dev)->is_ivybridge)
  1621. #define IS_IVB_GT1(dev) ((dev)->pdev->device == 0x0156 || \
  1622. (dev)->pdev->device == 0x0152 || \
  1623. (dev)->pdev->device == 0x015a)
  1624. #define IS_SNB_GT1(dev) ((dev)->pdev->device == 0x0102 || \
  1625. (dev)->pdev->device == 0x0106 || \
  1626. (dev)->pdev->device == 0x010A)
  1627. #define IS_VALLEYVIEW(dev) (INTEL_INFO(dev)->is_valleyview)
  1628. #define IS_CHERRYVIEW(dev) (INTEL_INFO(dev)->is_valleyview && IS_GEN8(dev))
  1629. #define IS_HASWELL(dev) (INTEL_INFO(dev)->is_haswell)
  1630. #define IS_BROADWELL(dev) (!INTEL_INFO(dev)->is_valleyview && IS_GEN8(dev))
  1631. #define IS_MOBILE(dev) (INTEL_INFO(dev)->is_mobile)
  1632. #define IS_HSW_EARLY_SDV(dev) (IS_HASWELL(dev) && \
  1633. ((dev)->pdev->device & 0xFF00) == 0x0C00)
  1634. #define IS_BDW_ULT(dev) (IS_BROADWELL(dev) && \
  1635. (((dev)->pdev->device & 0xf) == 0x2 || \
  1636. ((dev)->pdev->device & 0xf) == 0x6 || \
  1637. ((dev)->pdev->device & 0xf) == 0xe))
  1638. #define IS_HSW_ULT(dev) (IS_HASWELL(dev) && \
  1639. ((dev)->pdev->device & 0xFF00) == 0x0A00)
  1640. #define IS_ULT(dev) (IS_HSW_ULT(dev) || IS_BDW_ULT(dev))
  1641. #define IS_HSW_GT3(dev) (IS_HASWELL(dev) && \
  1642. ((dev)->pdev->device & 0x00F0) == 0x0020)
  1643. /* ULX machines are also considered ULT. */
  1644. #define IS_HSW_ULX(dev) ((dev)->pdev->device == 0x0A0E || \
  1645. (dev)->pdev->device == 0x0A1E)
  1646. #define IS_PRELIMINARY_HW(intel_info) ((intel_info)->is_preliminary)
  1647. /*
  1648. * The genX designation typically refers to the render engine, so render
  1649. * capability related checks should use IS_GEN, while display and other checks
  1650. * have their own (e.g. HAS_PCH_SPLIT for ILK+ display, IS_foo for particular
  1651. * chips, etc.).
  1652. */
  1653. #define IS_GEN2(dev) (INTEL_INFO(dev)->gen == 2)
  1654. #define IS_GEN3(dev) (INTEL_INFO(dev)->gen == 3)
  1655. #define IS_GEN4(dev) (INTEL_INFO(dev)->gen == 4)
  1656. #define IS_GEN5(dev) (INTEL_INFO(dev)->gen == 5)
  1657. #define IS_GEN6(dev) (INTEL_INFO(dev)->gen == 6)
  1658. #define IS_GEN7(dev) (INTEL_INFO(dev)->gen == 7)
  1659. #define IS_GEN8(dev) (INTEL_INFO(dev)->gen == 8)
  1660. #define RENDER_RING (1<<RCS)
  1661. #define BSD_RING (1<<VCS)
  1662. #define BLT_RING (1<<BCS)
  1663. #define VEBOX_RING (1<<VECS)
  1664. #define BSD2_RING (1<<VCS2)
  1665. #define HAS_BSD(dev) (INTEL_INFO(dev)->ring_mask & BSD_RING)
  1666. #define HAS_BSD2(dev) (INTEL_INFO(dev)->ring_mask & BSD2_RING)
  1667. #define HAS_BLT(dev) (INTEL_INFO(dev)->ring_mask & BLT_RING)
  1668. #define HAS_VEBOX(dev) (INTEL_INFO(dev)->ring_mask & VEBOX_RING)
  1669. #define HAS_LLC(dev) (INTEL_INFO(dev)->has_llc)
  1670. #define HAS_WT(dev) ((IS_HASWELL(dev) || IS_BROADWELL(dev)) && \
  1671. to_i915(dev)->ellc_size)
  1672. #define I915_NEED_GFX_HWS(dev) (INTEL_INFO(dev)->need_gfx_hws)
  1673. #define HAS_HW_CONTEXTS(dev) (INTEL_INFO(dev)->gen >= 6)
  1674. #define HAS_ALIASING_PPGTT(dev) (INTEL_INFO(dev)->gen >= 6 && \
  1675. (!IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)))
  1676. #define HAS_PPGTT(dev) (INTEL_INFO(dev)->gen >= 7 \
  1677. && !IS_GEN8(dev))
  1678. #define USES_PPGTT(dev) intel_enable_ppgtt(dev, false)
  1679. #define USES_FULL_PPGTT(dev) intel_enable_ppgtt(dev, true)
  1680. #define HAS_OVERLAY(dev) (INTEL_INFO(dev)->has_overlay)
  1681. #define OVERLAY_NEEDS_PHYSICAL(dev) (INTEL_INFO(dev)->overlay_needs_physical)
  1682. /* Early gen2 have a totally busted CS tlb and require pinned batches. */
  1683. #define HAS_BROKEN_CS_TLB(dev) (IS_I830(dev) || IS_845G(dev))
  1684. /*
  1685. * dp aux and gmbus irq on gen4 seems to be able to generate legacy interrupts
  1686. * even when in MSI mode. This results in spurious interrupt warnings if the
  1687. * legacy irq no. is shared with another device. The kernel then disables that
  1688. * interrupt source and so prevents the other device from working properly.
  1689. */
  1690. #define HAS_AUX_IRQ(dev) (INTEL_INFO(dev)->gen >= 5)
  1691. #define HAS_GMBUS_IRQ(dev) (INTEL_INFO(dev)->gen >= 5)
  1692. /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
  1693. * rows, which changed the alignment requirements and fence programming.
  1694. */
  1695. #define HAS_128_BYTE_Y_TILING(dev) (!IS_GEN2(dev) && !(IS_I915G(dev) || \
  1696. IS_I915GM(dev)))
  1697. #define SUPPORTS_DIGITAL_OUTPUTS(dev) (!IS_GEN2(dev) && !IS_PINEVIEW(dev))
  1698. #define SUPPORTS_INTEGRATED_HDMI(dev) (IS_G4X(dev) || IS_GEN5(dev))
  1699. #define SUPPORTS_INTEGRATED_DP(dev) (IS_G4X(dev) || IS_GEN5(dev))
  1700. #define SUPPORTS_TV(dev) (INTEL_INFO(dev)->supports_tv)
  1701. #define I915_HAS_HOTPLUG(dev) (INTEL_INFO(dev)->has_hotplug)
  1702. #define HAS_FW_BLC(dev) (INTEL_INFO(dev)->gen > 2)
  1703. #define HAS_PIPE_CXSR(dev) (INTEL_INFO(dev)->has_pipe_cxsr)
  1704. #define HAS_FBC(dev) (INTEL_INFO(dev)->has_fbc)
  1705. #define HAS_IPS(dev) (IS_ULT(dev) || IS_BROADWELL(dev))
  1706. #define HAS_DDI(dev) (INTEL_INFO(dev)->has_ddi)
  1707. #define HAS_FPGA_DBG_UNCLAIMED(dev) (INTEL_INFO(dev)->has_fpga_dbg)
  1708. #define HAS_PSR(dev) (IS_HASWELL(dev) || IS_BROADWELL(dev))
  1709. #define HAS_RUNTIME_PM(dev) (IS_GEN6(dev) || IS_HASWELL(dev) || \
  1710. IS_BROADWELL(dev) || IS_VALLEYVIEW(dev))
  1711. #define INTEL_PCH_DEVICE_ID_MASK 0xff00
  1712. #define INTEL_PCH_IBX_DEVICE_ID_TYPE 0x3b00
  1713. #define INTEL_PCH_CPT_DEVICE_ID_TYPE 0x1c00
  1714. #define INTEL_PCH_PPT_DEVICE_ID_TYPE 0x1e00
  1715. #define INTEL_PCH_LPT_DEVICE_ID_TYPE 0x8c00
  1716. #define INTEL_PCH_LPT_LP_DEVICE_ID_TYPE 0x9c00
  1717. #define INTEL_PCH_TYPE(dev) (to_i915(dev)->pch_type)
  1718. #define HAS_PCH_LPT(dev) (INTEL_PCH_TYPE(dev) == PCH_LPT)
  1719. #define HAS_PCH_CPT(dev) (INTEL_PCH_TYPE(dev) == PCH_CPT)
  1720. #define HAS_PCH_IBX(dev) (INTEL_PCH_TYPE(dev) == PCH_IBX)
  1721. #define HAS_PCH_NOP(dev) (INTEL_PCH_TYPE(dev) == PCH_NOP)
  1722. #define HAS_PCH_SPLIT(dev) (INTEL_PCH_TYPE(dev) != PCH_NONE)
  1723. /* DPF == dynamic parity feature */
  1724. #define HAS_L3_DPF(dev) (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  1725. #define NUM_L3_SLICES(dev) (IS_HSW_GT3(dev) ? 2 : HAS_L3_DPF(dev))
  1726. #define GT_FREQUENCY_MULTIPLIER 50
  1727. #include "i915_trace.h"
  1728. extern const struct drm_ioctl_desc i915_ioctls[];
  1729. extern int i915_max_ioctl;
  1730. extern int i915_suspend(struct drm_device *dev, pm_message_t state);
  1731. extern int i915_resume(struct drm_device *dev);
  1732. extern int i915_master_create(struct drm_device *dev, struct drm_master *master);
  1733. extern void i915_master_destroy(struct drm_device *dev, struct drm_master *master);
  1734. /* i915_params.c */
  1735. struct i915_params {
  1736. int modeset;
  1737. int panel_ignore_lid;
  1738. unsigned int powersave;
  1739. int semaphores;
  1740. unsigned int lvds_downclock;
  1741. int lvds_channel_mode;
  1742. int panel_use_ssc;
  1743. int vbt_sdvo_panel_type;
  1744. int enable_rc6;
  1745. int enable_fbc;
  1746. int enable_ppgtt;
  1747. int enable_psr;
  1748. unsigned int preliminary_hw_support;
  1749. int disable_power_well;
  1750. int enable_ips;
  1751. int invert_brightness;
  1752. int enable_cmd_parser;
  1753. /* leave bools at the end to not create holes */
  1754. bool enable_hangcheck;
  1755. bool fastboot;
  1756. bool prefault_disable;
  1757. bool reset;
  1758. bool disable_display;
  1759. bool disable_vtd_wa;
  1760. };
  1761. extern struct i915_params i915 __read_mostly;
  1762. /* i915_dma.c */
  1763. void i915_update_dri1_breadcrumb(struct drm_device *dev);
  1764. extern void i915_kernel_lost_context(struct drm_device * dev);
  1765. extern int i915_driver_load(struct drm_device *, unsigned long flags);
  1766. extern int i915_driver_unload(struct drm_device *);
  1767. extern int i915_driver_open(struct drm_device *dev, struct drm_file *file_priv);
  1768. extern void i915_driver_lastclose(struct drm_device * dev);
  1769. extern void i915_driver_preclose(struct drm_device *dev,
  1770. struct drm_file *file_priv);
  1771. extern void i915_driver_postclose(struct drm_device *dev,
  1772. struct drm_file *file_priv);
  1773. extern int i915_driver_device_is_agp(struct drm_device * dev);
  1774. #ifdef CONFIG_COMPAT
  1775. extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
  1776. unsigned long arg);
  1777. #endif
  1778. extern int i915_emit_box(struct drm_device *dev,
  1779. struct drm_clip_rect *box,
  1780. int DR1, int DR4);
  1781. extern int intel_gpu_reset(struct drm_device *dev);
  1782. extern int i915_reset(struct drm_device *dev);
  1783. extern unsigned long i915_chipset_val(struct drm_i915_private *dev_priv);
  1784. extern unsigned long i915_mch_val(struct drm_i915_private *dev_priv);
  1785. extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);
  1786. extern void i915_update_gfx_val(struct drm_i915_private *dev_priv);
  1787. int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool on);
  1788. extern void intel_console_resume(struct work_struct *work);
  1789. /* i915_irq.c */
  1790. void i915_queue_hangcheck(struct drm_device *dev);
  1791. __printf(3, 4)
  1792. void i915_handle_error(struct drm_device *dev, bool wedged,
  1793. const char *fmt, ...);
  1794. void gen6_set_pm_mask(struct drm_i915_private *dev_priv, u32 pm_iir,
  1795. int new_delay);
  1796. extern void intel_irq_init(struct drm_device *dev);
  1797. extern void intel_hpd_init(struct drm_device *dev);
  1798. extern void intel_uncore_sanitize(struct drm_device *dev);
  1799. extern void intel_uncore_early_sanitize(struct drm_device *dev);
  1800. extern void intel_uncore_init(struct drm_device *dev);
  1801. extern void intel_uncore_check_errors(struct drm_device *dev);
  1802. extern void intel_uncore_fini(struct drm_device *dev);
  1803. void
  1804. i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  1805. u32 status_mask);
  1806. void
  1807. i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  1808. u32 status_mask);
  1809. void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv);
  1810. void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv);
  1811. /* i915_gem.c */
  1812. int i915_gem_init_ioctl(struct drm_device *dev, void *data,
  1813. struct drm_file *file_priv);
  1814. int i915_gem_create_ioctl(struct drm_device *dev, void *data,
  1815. struct drm_file *file_priv);
  1816. int i915_gem_pread_ioctl(struct drm_device *dev, void *data,
  1817. struct drm_file *file_priv);
  1818. int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  1819. struct drm_file *file_priv);
  1820. int i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1821. struct drm_file *file_priv);
  1822. int i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data,
  1823. struct drm_file *file_priv);
  1824. int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  1825. struct drm_file *file_priv);
  1826. int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
  1827. struct drm_file *file_priv);
  1828. int i915_gem_execbuffer(struct drm_device *dev, void *data,
  1829. struct drm_file *file_priv);
  1830. int i915_gem_execbuffer2(struct drm_device *dev, void *data,
  1831. struct drm_file *file_priv);
  1832. int i915_gem_pin_ioctl(struct drm_device *dev, void *data,
  1833. struct drm_file *file_priv);
  1834. int i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
  1835. struct drm_file *file_priv);
  1836. int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
  1837. struct drm_file *file_priv);
  1838. int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data,
  1839. struct drm_file *file);
  1840. int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
  1841. struct drm_file *file);
  1842. int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
  1843. struct drm_file *file_priv);
  1844. int i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
  1845. struct drm_file *file_priv);
  1846. int i915_gem_entervt_ioctl(struct drm_device *dev, void *data,
  1847. struct drm_file *file_priv);
  1848. int i915_gem_leavevt_ioctl(struct drm_device *dev, void *data,
  1849. struct drm_file *file_priv);
  1850. int i915_gem_set_tiling(struct drm_device *dev, void *data,
  1851. struct drm_file *file_priv);
  1852. int i915_gem_get_tiling(struct drm_device *dev, void *data,
  1853. struct drm_file *file_priv);
  1854. int i915_gem_init_userptr(struct drm_device *dev);
  1855. int i915_gem_userptr_ioctl(struct drm_device *dev, void *data,
  1856. struct drm_file *file);
  1857. int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
  1858. struct drm_file *file_priv);
  1859. int i915_gem_wait_ioctl(struct drm_device *dev, void *data,
  1860. struct drm_file *file_priv);
  1861. void i915_gem_load(struct drm_device *dev);
  1862. void *i915_gem_object_alloc(struct drm_device *dev);
  1863. void i915_gem_object_free(struct drm_i915_gem_object *obj);
  1864. void i915_gem_object_init(struct drm_i915_gem_object *obj,
  1865. const struct drm_i915_gem_object_ops *ops);
  1866. struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev,
  1867. size_t size);
  1868. void i915_init_vm(struct drm_i915_private *dev_priv,
  1869. struct i915_address_space *vm);
  1870. void i915_gem_free_object(struct drm_gem_object *obj);
  1871. void i915_gem_vma_destroy(struct i915_vma *vma);
  1872. #define PIN_MAPPABLE 0x1
  1873. #define PIN_NONBLOCK 0x2
  1874. #define PIN_GLOBAL 0x4
  1875. #define PIN_OFFSET_BIAS 0x8
  1876. #define PIN_OFFSET_MASK (~4095)
  1877. int __must_check i915_gem_object_pin(struct drm_i915_gem_object *obj,
  1878. struct i915_address_space *vm,
  1879. uint32_t alignment,
  1880. uint64_t flags);
  1881. int __must_check i915_vma_unbind(struct i915_vma *vma);
  1882. int i915_gem_object_put_pages(struct drm_i915_gem_object *obj);
  1883. void i915_gem_release_all_mmaps(struct drm_i915_private *dev_priv);
  1884. void i915_gem_release_mmap(struct drm_i915_gem_object *obj);
  1885. void i915_gem_lastclose(struct drm_device *dev);
  1886. int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj,
  1887. int *needs_clflush);
  1888. int __must_check i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
  1889. static inline struct page *i915_gem_object_get_page(struct drm_i915_gem_object *obj, int n)
  1890. {
  1891. struct sg_page_iter sg_iter;
  1892. for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents, n)
  1893. return sg_page_iter_page(&sg_iter);
  1894. return NULL;
  1895. }
  1896. static inline void i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
  1897. {
  1898. BUG_ON(obj->pages == NULL);
  1899. obj->pages_pin_count++;
  1900. }
  1901. static inline void i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
  1902. {
  1903. BUG_ON(obj->pages_pin_count == 0);
  1904. obj->pages_pin_count--;
  1905. }
  1906. int __must_check i915_mutex_lock_interruptible(struct drm_device *dev);
  1907. int i915_gem_object_sync(struct drm_i915_gem_object *obj,
  1908. struct intel_engine_cs *to);
  1909. void i915_vma_move_to_active(struct i915_vma *vma,
  1910. struct intel_engine_cs *ring);
  1911. int i915_gem_dumb_create(struct drm_file *file_priv,
  1912. struct drm_device *dev,
  1913. struct drm_mode_create_dumb *args);
  1914. int i915_gem_mmap_gtt(struct drm_file *file_priv, struct drm_device *dev,
  1915. uint32_t handle, uint64_t *offset);
  1916. /**
  1917. * Returns true if seq1 is later than seq2.
  1918. */
  1919. static inline bool
  1920. i915_seqno_passed(uint32_t seq1, uint32_t seq2)
  1921. {
  1922. return (int32_t)(seq1 - seq2) >= 0;
  1923. }
  1924. int __must_check i915_gem_get_seqno(struct drm_device *dev, u32 *seqno);
  1925. int __must_check i915_gem_set_seqno(struct drm_device *dev, u32 seqno);
  1926. int __must_check i915_gem_object_get_fence(struct drm_i915_gem_object *obj);
  1927. int __must_check i915_gem_object_put_fence(struct drm_i915_gem_object *obj);
  1928. bool i915_gem_object_pin_fence(struct drm_i915_gem_object *obj);
  1929. void i915_gem_object_unpin_fence(struct drm_i915_gem_object *obj);
  1930. struct drm_i915_gem_request *
  1931. i915_gem_find_active_request(struct intel_engine_cs *ring);
  1932. bool i915_gem_retire_requests(struct drm_device *dev);
  1933. void i915_gem_retire_requests_ring(struct intel_engine_cs *ring);
  1934. int __must_check i915_gem_check_wedge(struct i915_gpu_error *error,
  1935. bool interruptible);
  1936. static inline bool i915_reset_in_progress(struct i915_gpu_error *error)
  1937. {
  1938. return unlikely(atomic_read(&error->reset_counter)
  1939. & (I915_RESET_IN_PROGRESS_FLAG | I915_WEDGED));
  1940. }
  1941. static inline bool i915_terminally_wedged(struct i915_gpu_error *error)
  1942. {
  1943. return atomic_read(&error->reset_counter) & I915_WEDGED;
  1944. }
  1945. static inline u32 i915_reset_count(struct i915_gpu_error *error)
  1946. {
  1947. return ((atomic_read(&error->reset_counter) & ~I915_WEDGED) + 1) / 2;
  1948. }
  1949. static inline bool i915_stop_ring_allow_ban(struct drm_i915_private *dev_priv)
  1950. {
  1951. return dev_priv->gpu_error.stop_rings == 0 ||
  1952. dev_priv->gpu_error.stop_rings & I915_STOP_RING_ALLOW_BAN;
  1953. }
  1954. static inline bool i915_stop_ring_allow_warn(struct drm_i915_private *dev_priv)
  1955. {
  1956. return dev_priv->gpu_error.stop_rings == 0 ||
  1957. dev_priv->gpu_error.stop_rings & I915_STOP_RING_ALLOW_WARN;
  1958. }
  1959. void i915_gem_reset(struct drm_device *dev);
  1960. bool i915_gem_clflush_object(struct drm_i915_gem_object *obj, bool force);
  1961. int __must_check i915_gem_object_finish_gpu(struct drm_i915_gem_object *obj);
  1962. int __must_check i915_gem_init(struct drm_device *dev);
  1963. int __must_check i915_gem_init_hw(struct drm_device *dev);
  1964. int i915_gem_l3_remap(struct intel_engine_cs *ring, int slice);
  1965. void i915_gem_init_swizzling(struct drm_device *dev);
  1966. void i915_gem_cleanup_ringbuffer(struct drm_device *dev);
  1967. int __must_check i915_gpu_idle(struct drm_device *dev);
  1968. int __must_check i915_gem_suspend(struct drm_device *dev);
  1969. int __i915_add_request(struct intel_engine_cs *ring,
  1970. struct drm_file *file,
  1971. struct drm_i915_gem_object *batch_obj,
  1972. u32 *seqno);
  1973. #define i915_add_request(ring, seqno) \
  1974. __i915_add_request(ring, NULL, NULL, seqno)
  1975. int __must_check i915_wait_seqno(struct intel_engine_cs *ring,
  1976. uint32_t seqno);
  1977. int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  1978. int __must_check
  1979. i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj,
  1980. bool write);
  1981. int __must_check
  1982. i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write);
  1983. int __must_check
  1984. i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
  1985. u32 alignment,
  1986. struct intel_engine_cs *pipelined);
  1987. void i915_gem_object_unpin_from_display_plane(struct drm_i915_gem_object *obj);
  1988. int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj,
  1989. int align);
  1990. int i915_gem_open(struct drm_device *dev, struct drm_file *file);
  1991. void i915_gem_release(struct drm_device *dev, struct drm_file *file);
  1992. uint32_t
  1993. i915_gem_get_gtt_size(struct drm_device *dev, uint32_t size, int tiling_mode);
  1994. uint32_t
  1995. i915_gem_get_gtt_alignment(struct drm_device *dev, uint32_t size,
  1996. int tiling_mode, bool fenced);
  1997. int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
  1998. enum i915_cache_level cache_level);
  1999. struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
  2000. struct dma_buf *dma_buf);
  2001. struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
  2002. struct drm_gem_object *gem_obj, int flags);
  2003. void i915_gem_restore_fences(struct drm_device *dev);
  2004. unsigned long i915_gem_obj_offset(struct drm_i915_gem_object *o,
  2005. struct i915_address_space *vm);
  2006. bool i915_gem_obj_bound_any(struct drm_i915_gem_object *o);
  2007. bool i915_gem_obj_bound(struct drm_i915_gem_object *o,
  2008. struct i915_address_space *vm);
  2009. unsigned long i915_gem_obj_size(struct drm_i915_gem_object *o,
  2010. struct i915_address_space *vm);
  2011. struct i915_vma *i915_gem_obj_to_vma(struct drm_i915_gem_object *obj,
  2012. struct i915_address_space *vm);
  2013. struct i915_vma *
  2014. i915_gem_obj_lookup_or_create_vma(struct drm_i915_gem_object *obj,
  2015. struct i915_address_space *vm);
  2016. struct i915_vma *i915_gem_obj_to_ggtt(struct drm_i915_gem_object *obj);
  2017. static inline bool i915_gem_obj_is_pinned(struct drm_i915_gem_object *obj) {
  2018. struct i915_vma *vma;
  2019. list_for_each_entry(vma, &obj->vma_list, vma_link)
  2020. if (vma->pin_count > 0)
  2021. return true;
  2022. return false;
  2023. }
  2024. /* Some GGTT VM helpers */
  2025. #define obj_to_ggtt(obj) \
  2026. (&((struct drm_i915_private *)(obj)->base.dev->dev_private)->gtt.base)
  2027. static inline bool i915_is_ggtt(struct i915_address_space *vm)
  2028. {
  2029. struct i915_address_space *ggtt =
  2030. &((struct drm_i915_private *)(vm)->dev->dev_private)->gtt.base;
  2031. return vm == ggtt;
  2032. }
  2033. static inline bool i915_gem_obj_ggtt_bound(struct drm_i915_gem_object *obj)
  2034. {
  2035. return i915_gem_obj_bound(obj, obj_to_ggtt(obj));
  2036. }
  2037. static inline unsigned long
  2038. i915_gem_obj_ggtt_offset(struct drm_i915_gem_object *obj)
  2039. {
  2040. return i915_gem_obj_offset(obj, obj_to_ggtt(obj));
  2041. }
  2042. static inline unsigned long
  2043. i915_gem_obj_ggtt_size(struct drm_i915_gem_object *obj)
  2044. {
  2045. return i915_gem_obj_size(obj, obj_to_ggtt(obj));
  2046. }
  2047. static inline int __must_check
  2048. i915_gem_obj_ggtt_pin(struct drm_i915_gem_object *obj,
  2049. uint32_t alignment,
  2050. unsigned flags)
  2051. {
  2052. return i915_gem_object_pin(obj, obj_to_ggtt(obj), alignment, flags | PIN_GLOBAL);
  2053. }
  2054. static inline int
  2055. i915_gem_object_ggtt_unbind(struct drm_i915_gem_object *obj)
  2056. {
  2057. return i915_vma_unbind(i915_gem_obj_to_ggtt(obj));
  2058. }
  2059. void i915_gem_object_ggtt_unpin(struct drm_i915_gem_object *obj);
  2060. /* i915_gem_context.c */
  2061. #define ctx_to_ppgtt(ctx) container_of((ctx)->vm, struct i915_hw_ppgtt, base)
  2062. int __must_check i915_gem_context_init(struct drm_device *dev);
  2063. void i915_gem_context_fini(struct drm_device *dev);
  2064. void i915_gem_context_reset(struct drm_device *dev);
  2065. int i915_gem_context_open(struct drm_device *dev, struct drm_file *file);
  2066. int i915_gem_context_enable(struct drm_i915_private *dev_priv);
  2067. void i915_gem_context_close(struct drm_device *dev, struct drm_file *file);
  2068. int i915_switch_context(struct intel_engine_cs *ring,
  2069. struct intel_context *to);
  2070. struct intel_context *
  2071. i915_gem_context_get(struct drm_i915_file_private *file_priv, u32 id);
  2072. void i915_gem_context_free(struct kref *ctx_ref);
  2073. static inline void i915_gem_context_reference(struct intel_context *ctx)
  2074. {
  2075. kref_get(&ctx->ref);
  2076. }
  2077. static inline void i915_gem_context_unreference(struct intel_context *ctx)
  2078. {
  2079. kref_put(&ctx->ref, i915_gem_context_free);
  2080. }
  2081. static inline bool i915_gem_context_is_default(const struct intel_context *c)
  2082. {
  2083. return c->id == DEFAULT_CONTEXT_ID;
  2084. }
  2085. int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
  2086. struct drm_file *file);
  2087. int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
  2088. struct drm_file *file);
  2089. /* i915_gem_render_state.c */
  2090. int i915_gem_render_state_init(struct intel_engine_cs *ring);
  2091. /* i915_gem_evict.c */
  2092. int __must_check i915_gem_evict_something(struct drm_device *dev,
  2093. struct i915_address_space *vm,
  2094. int min_size,
  2095. unsigned alignment,
  2096. unsigned cache_level,
  2097. unsigned long start,
  2098. unsigned long end,
  2099. unsigned flags);
  2100. int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle);
  2101. int i915_gem_evict_everything(struct drm_device *dev);
  2102. /* belongs in i915_gem_gtt.h */
  2103. static inline void i915_gem_chipset_flush(struct drm_device *dev)
  2104. {
  2105. if (INTEL_INFO(dev)->gen < 6)
  2106. intel_gtt_chipset_flush();
  2107. }
  2108. /* i915_gem_stolen.c */
  2109. int i915_gem_init_stolen(struct drm_device *dev);
  2110. int i915_gem_stolen_setup_compression(struct drm_device *dev, int size);
  2111. void i915_gem_stolen_cleanup_compression(struct drm_device *dev);
  2112. void i915_gem_cleanup_stolen(struct drm_device *dev);
  2113. struct drm_i915_gem_object *
  2114. i915_gem_object_create_stolen(struct drm_device *dev, u32 size);
  2115. struct drm_i915_gem_object *
  2116. i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
  2117. u32 stolen_offset,
  2118. u32 gtt_offset,
  2119. u32 size);
  2120. void i915_gem_object_release_stolen(struct drm_i915_gem_object *obj);
  2121. /* i915_gem_tiling.c */
  2122. static inline bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj)
  2123. {
  2124. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  2125. return dev_priv->mm.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_9_10_17 &&
  2126. obj->tiling_mode != I915_TILING_NONE;
  2127. }
  2128. void i915_gem_detect_bit_6_swizzle(struct drm_device *dev);
  2129. void i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj);
  2130. void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj);
  2131. /* i915_gem_debug.c */
  2132. #if WATCH_LISTS
  2133. int i915_verify_lists(struct drm_device *dev);
  2134. #else
  2135. #define i915_verify_lists(dev) 0
  2136. #endif
  2137. /* i915_debugfs.c */
  2138. int i915_debugfs_init(struct drm_minor *minor);
  2139. void i915_debugfs_cleanup(struct drm_minor *minor);
  2140. #ifdef CONFIG_DEBUG_FS
  2141. void intel_display_crc_init(struct drm_device *dev);
  2142. #else
  2143. static inline void intel_display_crc_init(struct drm_device *dev) {}
  2144. #endif
  2145. /* i915_gpu_error.c */
  2146. __printf(2, 3)
  2147. void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...);
  2148. int i915_error_state_to_str(struct drm_i915_error_state_buf *estr,
  2149. const struct i915_error_state_file_priv *error);
  2150. int i915_error_state_buf_init(struct drm_i915_error_state_buf *eb,
  2151. size_t count, loff_t pos);
  2152. static inline void i915_error_state_buf_release(
  2153. struct drm_i915_error_state_buf *eb)
  2154. {
  2155. kfree(eb->buf);
  2156. }
  2157. void i915_capture_error_state(struct drm_device *dev, bool wedge,
  2158. const char *error_msg);
  2159. void i915_error_state_get(struct drm_device *dev,
  2160. struct i915_error_state_file_priv *error_priv);
  2161. void i915_error_state_put(struct i915_error_state_file_priv *error_priv);
  2162. void i915_destroy_error_state(struct drm_device *dev);
  2163. void i915_get_extra_instdone(struct drm_device *dev, uint32_t *instdone);
  2164. const char *i915_cache_level_str(int type);
  2165. /* i915_cmd_parser.c */
  2166. int i915_cmd_parser_get_version(void);
  2167. int i915_cmd_parser_init_ring(struct intel_engine_cs *ring);
  2168. void i915_cmd_parser_fini_ring(struct intel_engine_cs *ring);
  2169. bool i915_needs_cmd_parser(struct intel_engine_cs *ring);
  2170. int i915_parse_cmds(struct intel_engine_cs *ring,
  2171. struct drm_i915_gem_object *batch_obj,
  2172. u32 batch_start_offset,
  2173. bool is_master);
  2174. /* i915_suspend.c */
  2175. extern int i915_save_state(struct drm_device *dev);
  2176. extern int i915_restore_state(struct drm_device *dev);
  2177. /* i915_ums.c */
  2178. void i915_save_display_reg(struct drm_device *dev);
  2179. void i915_restore_display_reg(struct drm_device *dev);
  2180. /* i915_sysfs.c */
  2181. void i915_setup_sysfs(struct drm_device *dev_priv);
  2182. void i915_teardown_sysfs(struct drm_device *dev_priv);
  2183. /* intel_i2c.c */
  2184. extern int intel_setup_gmbus(struct drm_device *dev);
  2185. extern void intel_teardown_gmbus(struct drm_device *dev);
  2186. static inline bool intel_gmbus_is_port_valid(unsigned port)
  2187. {
  2188. return (port >= GMBUS_PORT_SSC && port <= GMBUS_PORT_DPD);
  2189. }
  2190. extern struct i2c_adapter *intel_gmbus_get_adapter(
  2191. struct drm_i915_private *dev_priv, unsigned port);
  2192. extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
  2193. extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
  2194. static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
  2195. {
  2196. return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
  2197. }
  2198. extern void intel_i2c_reset(struct drm_device *dev);
  2199. /* intel_opregion.c */
  2200. struct intel_encoder;
  2201. #ifdef CONFIG_ACPI
  2202. extern int intel_opregion_setup(struct drm_device *dev);
  2203. extern void intel_opregion_init(struct drm_device *dev);
  2204. extern void intel_opregion_fini(struct drm_device *dev);
  2205. extern void intel_opregion_asle_intr(struct drm_device *dev);
  2206. extern int intel_opregion_notify_encoder(struct intel_encoder *intel_encoder,
  2207. bool enable);
  2208. extern int intel_opregion_notify_adapter(struct drm_device *dev,
  2209. pci_power_t state);
  2210. #else
  2211. static inline int intel_opregion_setup(struct drm_device *dev) { return 0; }
  2212. static inline void intel_opregion_init(struct drm_device *dev) { return; }
  2213. static inline void intel_opregion_fini(struct drm_device *dev) { return; }
  2214. static inline void intel_opregion_asle_intr(struct drm_device *dev) { return; }
  2215. static inline int
  2216. intel_opregion_notify_encoder(struct intel_encoder *intel_encoder, bool enable)
  2217. {
  2218. return 0;
  2219. }
  2220. static inline int
  2221. intel_opregion_notify_adapter(struct drm_device *dev, pci_power_t state)
  2222. {
  2223. return 0;
  2224. }
  2225. #endif
  2226. /* intel_acpi.c */
  2227. #ifdef CONFIG_ACPI
  2228. extern void intel_register_dsm_handler(void);
  2229. extern void intel_unregister_dsm_handler(void);
  2230. #else
  2231. static inline void intel_register_dsm_handler(void) { return; }
  2232. static inline void intel_unregister_dsm_handler(void) { return; }
  2233. #endif /* CONFIG_ACPI */
  2234. /* modesetting */
  2235. extern void intel_modeset_init_hw(struct drm_device *dev);
  2236. extern void intel_modeset_suspend_hw(struct drm_device *dev);
  2237. extern void intel_modeset_init(struct drm_device *dev);
  2238. extern void intel_modeset_gem_init(struct drm_device *dev);
  2239. extern void intel_modeset_cleanup(struct drm_device *dev);
  2240. extern void intel_connector_unregister(struct intel_connector *);
  2241. extern int intel_modeset_vga_set_state(struct drm_device *dev, bool state);
  2242. extern void intel_modeset_setup_hw_state(struct drm_device *dev,
  2243. bool force_restore);
  2244. extern void i915_redisable_vga(struct drm_device *dev);
  2245. extern void i915_redisable_vga_power_on(struct drm_device *dev);
  2246. extern bool intel_fbc_enabled(struct drm_device *dev);
  2247. extern void intel_disable_fbc(struct drm_device *dev);
  2248. extern bool ironlake_set_drps(struct drm_device *dev, u8 val);
  2249. extern void intel_init_pch_refclk(struct drm_device *dev);
  2250. extern void gen6_set_rps(struct drm_device *dev, u8 val);
  2251. extern void valleyview_set_rps(struct drm_device *dev, u8 val);
  2252. extern int valleyview_rps_max_freq(struct drm_i915_private *dev_priv);
  2253. extern int valleyview_rps_min_freq(struct drm_i915_private *dev_priv);
  2254. extern void intel_detect_pch(struct drm_device *dev);
  2255. extern int intel_trans_dp_port_sel(struct drm_crtc *crtc);
  2256. extern int intel_enable_rc6(const struct drm_device *dev);
  2257. extern bool i915_semaphore_is_enabled(struct drm_device *dev);
  2258. int i915_reg_read_ioctl(struct drm_device *dev, void *data,
  2259. struct drm_file *file);
  2260. int i915_get_reset_stats_ioctl(struct drm_device *dev, void *data,
  2261. struct drm_file *file);
  2262. /* overlay */
  2263. extern struct intel_overlay_error_state *intel_overlay_capture_error_state(struct drm_device *dev);
  2264. extern void intel_overlay_print_error_state(struct drm_i915_error_state_buf *e,
  2265. struct intel_overlay_error_state *error);
  2266. extern struct intel_display_error_state *intel_display_capture_error_state(struct drm_device *dev);
  2267. extern void intel_display_print_error_state(struct drm_i915_error_state_buf *e,
  2268. struct drm_device *dev,
  2269. struct intel_display_error_state *error);
  2270. /* On SNB platform, before reading ring registers forcewake bit
  2271. * must be set to prevent GT core from power down and stale values being
  2272. * returned.
  2273. */
  2274. void gen6_gt_force_wake_get(struct drm_i915_private *dev_priv, int fw_engine);
  2275. void gen6_gt_force_wake_put(struct drm_i915_private *dev_priv, int fw_engine);
  2276. void assert_force_wake_inactive(struct drm_i915_private *dev_priv);
  2277. int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u8 mbox, u32 *val);
  2278. int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u8 mbox, u32 val);
  2279. /* intel_sideband.c */
  2280. u32 vlv_punit_read(struct drm_i915_private *dev_priv, u8 addr);
  2281. void vlv_punit_write(struct drm_i915_private *dev_priv, u8 addr, u32 val);
  2282. u32 vlv_nc_read(struct drm_i915_private *dev_priv, u8 addr);
  2283. u32 vlv_gpio_nc_read(struct drm_i915_private *dev_priv, u32 reg);
  2284. void vlv_gpio_nc_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2285. u32 vlv_cck_read(struct drm_i915_private *dev_priv, u32 reg);
  2286. void vlv_cck_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2287. u32 vlv_ccu_read(struct drm_i915_private *dev_priv, u32 reg);
  2288. void vlv_ccu_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2289. u32 vlv_bunit_read(struct drm_i915_private *dev_priv, u32 reg);
  2290. void vlv_bunit_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2291. u32 vlv_gps_core_read(struct drm_i915_private *dev_priv, u32 reg);
  2292. void vlv_gps_core_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2293. u32 vlv_dpio_read(struct drm_i915_private *dev_priv, enum pipe pipe, int reg);
  2294. void vlv_dpio_write(struct drm_i915_private *dev_priv, enum pipe pipe, int reg, u32 val);
  2295. u32 intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg,
  2296. enum intel_sbi_destination destination);
  2297. void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
  2298. enum intel_sbi_destination destination);
  2299. u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
  2300. void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2301. int vlv_gpu_freq(struct drm_i915_private *dev_priv, int val);
  2302. int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val);
  2303. #define FORCEWAKE_RENDER (1 << 0)
  2304. #define FORCEWAKE_MEDIA (1 << 1)
  2305. #define FORCEWAKE_ALL (FORCEWAKE_RENDER | FORCEWAKE_MEDIA)
  2306. #define I915_READ8(reg) dev_priv->uncore.funcs.mmio_readb(dev_priv, (reg), true)
  2307. #define I915_WRITE8(reg, val) dev_priv->uncore.funcs.mmio_writeb(dev_priv, (reg), (val), true)
  2308. #define I915_READ16(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), true)
  2309. #define I915_WRITE16(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), true)
  2310. #define I915_READ16_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), false)
  2311. #define I915_WRITE16_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), false)
  2312. #define I915_READ(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), true)
  2313. #define I915_WRITE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), true)
  2314. #define I915_READ_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), false)
  2315. #define I915_WRITE_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), false)
  2316. /* Be very careful with read/write 64-bit values. On 32-bit machines, they
  2317. * will be implemented using 2 32-bit writes in an arbitrary order with
  2318. * an arbitrary delay between them. This can cause the hardware to
  2319. * act upon the intermediate value, possibly leading to corruption and
  2320. * machine death. You have been warned.
  2321. */
  2322. #define I915_WRITE64(reg, val) dev_priv->uncore.funcs.mmio_writeq(dev_priv, (reg), (val), true)
  2323. #define I915_READ64(reg) dev_priv->uncore.funcs.mmio_readq(dev_priv, (reg), true)
  2324. #define I915_READ64_2x32(lower_reg, upper_reg) ({ \
  2325. u32 upper = I915_READ(upper_reg); \
  2326. u32 lower = I915_READ(lower_reg); \
  2327. u32 tmp = I915_READ(upper_reg); \
  2328. if (upper != tmp) { \
  2329. upper = tmp; \
  2330. lower = I915_READ(lower_reg); \
  2331. WARN_ON(I915_READ(upper_reg) != upper); \
  2332. } \
  2333. (u64)upper << 32 | lower; })
  2334. #define POSTING_READ(reg) (void)I915_READ_NOTRACE(reg)
  2335. #define POSTING_READ16(reg) (void)I915_READ16_NOTRACE(reg)
  2336. /* "Broadcast RGB" property */
  2337. #define INTEL_BROADCAST_RGB_AUTO 0
  2338. #define INTEL_BROADCAST_RGB_FULL 1
  2339. #define INTEL_BROADCAST_RGB_LIMITED 2
  2340. static inline uint32_t i915_vgacntrl_reg(struct drm_device *dev)
  2341. {
  2342. if (HAS_PCH_SPLIT(dev))
  2343. return CPU_VGACNTRL;
  2344. else if (IS_VALLEYVIEW(dev))
  2345. return VLV_VGACNTRL;
  2346. else
  2347. return VGACNTRL;
  2348. }
  2349. static inline void __user *to_user_ptr(u64 address)
  2350. {
  2351. return (void __user *)(uintptr_t)address;
  2352. }
  2353. static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
  2354. {
  2355. unsigned long j = msecs_to_jiffies(m);
  2356. return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
  2357. }
  2358. static inline unsigned long
  2359. timespec_to_jiffies_timeout(const struct timespec *value)
  2360. {
  2361. unsigned long j = timespec_to_jiffies(value);
  2362. return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
  2363. }
  2364. /*
  2365. * If you need to wait X milliseconds between events A and B, but event B
  2366. * doesn't happen exactly after event A, you record the timestamp (jiffies) of
  2367. * when event A happened, then just before event B you call this function and
  2368. * pass the timestamp as the first argument, and X as the second argument.
  2369. */
  2370. static inline void
  2371. wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)
  2372. {
  2373. unsigned long target_jiffies, tmp_jiffies, remaining_jiffies;
  2374. /*
  2375. * Don't re-read the value of "jiffies" every time since it may change
  2376. * behind our back and break the math.
  2377. */
  2378. tmp_jiffies = jiffies;
  2379. target_jiffies = timestamp_jiffies +
  2380. msecs_to_jiffies_timeout(to_wait_ms);
  2381. if (time_after(target_jiffies, tmp_jiffies)) {
  2382. remaining_jiffies = target_jiffies - tmp_jiffies;
  2383. while (remaining_jiffies)
  2384. remaining_jiffies =
  2385. schedule_timeout_uninterruptible(remaining_jiffies);
  2386. }
  2387. }
  2388. #endif