i915_drv.h 89 KB

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