vmwgfx_execbuf.c 125 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327
  1. /**************************************************************************
  2. *
  3. * Copyright © 2009 - 2015 VMware, Inc., Palo Alto, CA., USA
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  22. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  24. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. #include "vmwgfx_drv.h"
  28. #include "vmwgfx_reg.h"
  29. #include <drm/ttm/ttm_bo_api.h>
  30. #include <drm/ttm/ttm_placement.h>
  31. #include "vmwgfx_so.h"
  32. #include "vmwgfx_binding.h"
  33. #define VMW_RES_HT_ORDER 12
  34. /**
  35. * struct vmw_resource_relocation - Relocation info for resources
  36. *
  37. * @head: List head for the software context's relocation list.
  38. * @res: Non-ref-counted pointer to the resource.
  39. * @offset: Offset of 4 byte entries into the command buffer where the
  40. * id that needs fixup is located.
  41. */
  42. struct vmw_resource_relocation {
  43. struct list_head head;
  44. const struct vmw_resource *res;
  45. unsigned long offset;
  46. };
  47. /**
  48. * struct vmw_resource_val_node - Validation info for resources
  49. *
  50. * @head: List head for the software context's resource list.
  51. * @hash: Hash entry for quick resouce to val_node lookup.
  52. * @res: Ref-counted pointer to the resource.
  53. * @switch_backup: Boolean whether to switch backup buffer on unreserve.
  54. * @new_backup: Refcounted pointer to the new backup buffer.
  55. * @staged_bindings: If @res is a context, tracks bindings set up during
  56. * the command batch. Otherwise NULL.
  57. * @new_backup_offset: New backup buffer offset if @new_backup is non-NUll.
  58. * @first_usage: Set to true the first time the resource is referenced in
  59. * the command stream.
  60. * @switching_backup: The command stream provides a new backup buffer for a
  61. * resource.
  62. * @no_buffer_needed: This means @switching_backup is true on first buffer
  63. * reference. So resource reservation does not need to allocate a backup
  64. * buffer for the resource.
  65. */
  66. struct vmw_resource_val_node {
  67. struct list_head head;
  68. struct drm_hash_item hash;
  69. struct vmw_resource *res;
  70. struct vmw_dma_buffer *new_backup;
  71. struct vmw_ctx_binding_state *staged_bindings;
  72. unsigned long new_backup_offset;
  73. u32 first_usage : 1;
  74. u32 switching_backup : 1;
  75. u32 no_buffer_needed : 1;
  76. };
  77. /**
  78. * struct vmw_cmd_entry - Describe a command for the verifier
  79. *
  80. * @user_allow: Whether allowed from the execbuf ioctl.
  81. * @gb_disable: Whether disabled if guest-backed objects are available.
  82. * @gb_enable: Whether enabled iff guest-backed objects are available.
  83. */
  84. struct vmw_cmd_entry {
  85. int (*func) (struct vmw_private *, struct vmw_sw_context *,
  86. SVGA3dCmdHeader *);
  87. bool user_allow;
  88. bool gb_disable;
  89. bool gb_enable;
  90. };
  91. #define VMW_CMD_DEF(_cmd, _func, _user_allow, _gb_disable, _gb_enable) \
  92. [(_cmd) - SVGA_3D_CMD_BASE] = {(_func), (_user_allow),\
  93. (_gb_disable), (_gb_enable)}
  94. static int vmw_resource_context_res_add(struct vmw_private *dev_priv,
  95. struct vmw_sw_context *sw_context,
  96. struct vmw_resource *ctx);
  97. static int vmw_translate_mob_ptr(struct vmw_private *dev_priv,
  98. struct vmw_sw_context *sw_context,
  99. SVGAMobId *id,
  100. struct vmw_dma_buffer **vmw_bo_p);
  101. static int vmw_bo_to_validate_list(struct vmw_sw_context *sw_context,
  102. struct vmw_dma_buffer *vbo,
  103. bool validate_as_mob,
  104. uint32_t *p_val_node);
  105. /**
  106. * vmw_resources_unreserve - unreserve resources previously reserved for
  107. * command submission.
  108. *
  109. * @sw_context: pointer to the software context
  110. * @backoff: Whether command submission failed.
  111. */
  112. static void vmw_resources_unreserve(struct vmw_sw_context *sw_context,
  113. bool backoff)
  114. {
  115. struct vmw_resource_val_node *val;
  116. struct list_head *list = &sw_context->resource_list;
  117. if (sw_context->dx_query_mob && !backoff)
  118. vmw_context_bind_dx_query(sw_context->dx_query_ctx,
  119. sw_context->dx_query_mob);
  120. list_for_each_entry(val, list, head) {
  121. struct vmw_resource *res = val->res;
  122. bool switch_backup =
  123. (backoff) ? false : val->switching_backup;
  124. /*
  125. * Transfer staged context bindings to the
  126. * persistent context binding tracker.
  127. */
  128. if (unlikely(val->staged_bindings)) {
  129. if (!backoff) {
  130. vmw_binding_state_commit
  131. (vmw_context_binding_state(val->res),
  132. val->staged_bindings);
  133. }
  134. if (val->staged_bindings != sw_context->staged_bindings)
  135. vmw_binding_state_free(val->staged_bindings);
  136. else
  137. sw_context->staged_bindings_inuse = false;
  138. val->staged_bindings = NULL;
  139. }
  140. vmw_resource_unreserve(res, switch_backup, val->new_backup,
  141. val->new_backup_offset);
  142. vmw_dmabuf_unreference(&val->new_backup);
  143. }
  144. }
  145. /**
  146. * vmw_cmd_ctx_first_setup - Perform the setup needed when a context is
  147. * added to the validate list.
  148. *
  149. * @dev_priv: Pointer to the device private:
  150. * @sw_context: The validation context:
  151. * @node: The validation node holding this context.
  152. */
  153. static int vmw_cmd_ctx_first_setup(struct vmw_private *dev_priv,
  154. struct vmw_sw_context *sw_context,
  155. struct vmw_resource_val_node *node)
  156. {
  157. int ret;
  158. ret = vmw_resource_context_res_add(dev_priv, sw_context, node->res);
  159. if (unlikely(ret != 0))
  160. goto out_err;
  161. if (!sw_context->staged_bindings) {
  162. sw_context->staged_bindings =
  163. vmw_binding_state_alloc(dev_priv);
  164. if (IS_ERR(sw_context->staged_bindings)) {
  165. DRM_ERROR("Failed to allocate context binding "
  166. "information.\n");
  167. ret = PTR_ERR(sw_context->staged_bindings);
  168. sw_context->staged_bindings = NULL;
  169. goto out_err;
  170. }
  171. }
  172. if (sw_context->staged_bindings_inuse) {
  173. node->staged_bindings = vmw_binding_state_alloc(dev_priv);
  174. if (IS_ERR(node->staged_bindings)) {
  175. DRM_ERROR("Failed to allocate context binding "
  176. "information.\n");
  177. ret = PTR_ERR(node->staged_bindings);
  178. node->staged_bindings = NULL;
  179. goto out_err;
  180. }
  181. } else {
  182. node->staged_bindings = sw_context->staged_bindings;
  183. sw_context->staged_bindings_inuse = true;
  184. }
  185. return 0;
  186. out_err:
  187. return ret;
  188. }
  189. /**
  190. * vmw_resource_val_add - Add a resource to the software context's
  191. * resource list if it's not already on it.
  192. *
  193. * @sw_context: Pointer to the software context.
  194. * @res: Pointer to the resource.
  195. * @p_node On successful return points to a valid pointer to a
  196. * struct vmw_resource_val_node, if non-NULL on entry.
  197. */
  198. static int vmw_resource_val_add(struct vmw_sw_context *sw_context,
  199. struct vmw_resource *res,
  200. struct vmw_resource_val_node **p_node)
  201. {
  202. struct vmw_private *dev_priv = res->dev_priv;
  203. struct vmw_resource_val_node *node;
  204. struct drm_hash_item *hash;
  205. int ret;
  206. if (likely(drm_ht_find_item(&sw_context->res_ht, (unsigned long) res,
  207. &hash) == 0)) {
  208. node = container_of(hash, struct vmw_resource_val_node, hash);
  209. node->first_usage = false;
  210. if (unlikely(p_node != NULL))
  211. *p_node = node;
  212. return 0;
  213. }
  214. node = kzalloc(sizeof(*node), GFP_KERNEL);
  215. if (unlikely(node == NULL)) {
  216. DRM_ERROR("Failed to allocate a resource validation "
  217. "entry.\n");
  218. return -ENOMEM;
  219. }
  220. node->hash.key = (unsigned long) res;
  221. ret = drm_ht_insert_item(&sw_context->res_ht, &node->hash);
  222. if (unlikely(ret != 0)) {
  223. DRM_ERROR("Failed to initialize a resource validation "
  224. "entry.\n");
  225. kfree(node);
  226. return ret;
  227. }
  228. node->res = vmw_resource_reference(res);
  229. node->first_usage = true;
  230. if (unlikely(p_node != NULL))
  231. *p_node = node;
  232. if (!dev_priv->has_mob) {
  233. list_add_tail(&node->head, &sw_context->resource_list);
  234. return 0;
  235. }
  236. switch (vmw_res_type(res)) {
  237. case vmw_res_context:
  238. case vmw_res_dx_context:
  239. list_add(&node->head, &sw_context->ctx_resource_list);
  240. ret = vmw_cmd_ctx_first_setup(dev_priv, sw_context, node);
  241. break;
  242. case vmw_res_cotable:
  243. list_add_tail(&node->head, &sw_context->ctx_resource_list);
  244. break;
  245. default:
  246. list_add_tail(&node->head, &sw_context->resource_list);
  247. break;
  248. }
  249. return ret;
  250. }
  251. /**
  252. * vmw_view_res_val_add - Add a view and the surface it's pointing to
  253. * to the validation list
  254. *
  255. * @sw_context: The software context holding the validation list.
  256. * @view: Pointer to the view resource.
  257. *
  258. * Returns 0 if success, negative error code otherwise.
  259. */
  260. static int vmw_view_res_val_add(struct vmw_sw_context *sw_context,
  261. struct vmw_resource *view)
  262. {
  263. int ret;
  264. /*
  265. * First add the resource the view is pointing to, otherwise
  266. * it may be swapped out when the view is validated.
  267. */
  268. ret = vmw_resource_val_add(sw_context, vmw_view_srf(view), NULL);
  269. if (ret)
  270. return ret;
  271. return vmw_resource_val_add(sw_context, view, NULL);
  272. }
  273. /**
  274. * vmw_view_id_val_add - Look up a view and add it and the surface it's
  275. * pointing to to the validation list.
  276. *
  277. * @sw_context: The software context holding the validation list.
  278. * @view_type: The view type to look up.
  279. * @id: view id of the view.
  280. *
  281. * The view is represented by a view id and the DX context it's created on,
  282. * or scheduled for creation on. If there is no DX context set, the function
  283. * will return -EINVAL. Otherwise returns 0 on success and -EINVAL on failure.
  284. */
  285. static int vmw_view_id_val_add(struct vmw_sw_context *sw_context,
  286. enum vmw_view_type view_type, u32 id)
  287. {
  288. struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
  289. struct vmw_resource *view;
  290. int ret;
  291. if (!ctx_node) {
  292. DRM_ERROR("DX Context not set.\n");
  293. return -EINVAL;
  294. }
  295. view = vmw_view_lookup(sw_context->man, view_type, id);
  296. if (IS_ERR(view))
  297. return PTR_ERR(view);
  298. ret = vmw_view_res_val_add(sw_context, view);
  299. vmw_resource_unreference(&view);
  300. return ret;
  301. }
  302. /**
  303. * vmw_resource_context_res_add - Put resources previously bound to a context on
  304. * the validation list
  305. *
  306. * @dev_priv: Pointer to a device private structure
  307. * @sw_context: Pointer to a software context used for this command submission
  308. * @ctx: Pointer to the context resource
  309. *
  310. * This function puts all resources that were previously bound to @ctx on
  311. * the resource validation list. This is part of the context state reemission
  312. */
  313. static int vmw_resource_context_res_add(struct vmw_private *dev_priv,
  314. struct vmw_sw_context *sw_context,
  315. struct vmw_resource *ctx)
  316. {
  317. struct list_head *binding_list;
  318. struct vmw_ctx_bindinfo *entry;
  319. int ret = 0;
  320. struct vmw_resource *res;
  321. u32 i;
  322. /* Add all cotables to the validation list. */
  323. if (dev_priv->has_dx && vmw_res_type(ctx) == vmw_res_dx_context) {
  324. for (i = 0; i < SVGA_COTABLE_DX10_MAX; ++i) {
  325. res = vmw_context_cotable(ctx, i);
  326. if (IS_ERR(res))
  327. continue;
  328. ret = vmw_resource_val_add(sw_context, res, NULL);
  329. vmw_resource_unreference(&res);
  330. if (unlikely(ret != 0))
  331. return ret;
  332. }
  333. }
  334. /* Add all resources bound to the context to the validation list */
  335. mutex_lock(&dev_priv->binding_mutex);
  336. binding_list = vmw_context_binding_list(ctx);
  337. list_for_each_entry(entry, binding_list, ctx_list) {
  338. /* entry->res is not refcounted */
  339. res = vmw_resource_reference_unless_doomed(entry->res);
  340. if (unlikely(res == NULL))
  341. continue;
  342. if (vmw_res_type(entry->res) == vmw_res_view)
  343. ret = vmw_view_res_val_add(sw_context, entry->res);
  344. else
  345. ret = vmw_resource_val_add(sw_context, entry->res,
  346. NULL);
  347. vmw_resource_unreference(&res);
  348. if (unlikely(ret != 0))
  349. break;
  350. }
  351. if (dev_priv->has_dx && vmw_res_type(ctx) == vmw_res_dx_context) {
  352. struct vmw_dma_buffer *dx_query_mob;
  353. dx_query_mob = vmw_context_get_dx_query_mob(ctx);
  354. if (dx_query_mob)
  355. ret = vmw_bo_to_validate_list(sw_context,
  356. dx_query_mob,
  357. true, NULL);
  358. }
  359. mutex_unlock(&dev_priv->binding_mutex);
  360. return ret;
  361. }
  362. /**
  363. * vmw_resource_relocation_add - Add a relocation to the relocation list
  364. *
  365. * @list: Pointer to head of relocation list.
  366. * @res: The resource.
  367. * @offset: Offset into the command buffer currently being parsed where the
  368. * id that needs fixup is located. Granularity is 4 bytes.
  369. */
  370. static int vmw_resource_relocation_add(struct list_head *list,
  371. const struct vmw_resource *res,
  372. unsigned long offset)
  373. {
  374. struct vmw_resource_relocation *rel;
  375. rel = kmalloc(sizeof(*rel), GFP_KERNEL);
  376. if (unlikely(rel == NULL)) {
  377. DRM_ERROR("Failed to allocate a resource relocation.\n");
  378. return -ENOMEM;
  379. }
  380. rel->res = res;
  381. rel->offset = offset;
  382. list_add_tail(&rel->head, list);
  383. return 0;
  384. }
  385. /**
  386. * vmw_resource_relocations_free - Free all relocations on a list
  387. *
  388. * @list: Pointer to the head of the relocation list.
  389. */
  390. static void vmw_resource_relocations_free(struct list_head *list)
  391. {
  392. struct vmw_resource_relocation *rel, *n;
  393. list_for_each_entry_safe(rel, n, list, head) {
  394. list_del(&rel->head);
  395. kfree(rel);
  396. }
  397. }
  398. /**
  399. * vmw_resource_relocations_apply - Apply all relocations on a list
  400. *
  401. * @cb: Pointer to the start of the command buffer bein patch. This need
  402. * not be the same buffer as the one being parsed when the relocation
  403. * list was built, but the contents must be the same modulo the
  404. * resource ids.
  405. * @list: Pointer to the head of the relocation list.
  406. */
  407. static void vmw_resource_relocations_apply(uint32_t *cb,
  408. struct list_head *list)
  409. {
  410. struct vmw_resource_relocation *rel;
  411. list_for_each_entry(rel, list, head) {
  412. if (likely(rel->res != NULL))
  413. cb[rel->offset] = rel->res->id;
  414. else
  415. cb[rel->offset] = SVGA_3D_CMD_NOP;
  416. }
  417. }
  418. static int vmw_cmd_invalid(struct vmw_private *dev_priv,
  419. struct vmw_sw_context *sw_context,
  420. SVGA3dCmdHeader *header)
  421. {
  422. return capable(CAP_SYS_ADMIN) ? : -EINVAL;
  423. }
  424. static int vmw_cmd_ok(struct vmw_private *dev_priv,
  425. struct vmw_sw_context *sw_context,
  426. SVGA3dCmdHeader *header)
  427. {
  428. return 0;
  429. }
  430. /**
  431. * vmw_bo_to_validate_list - add a bo to a validate list
  432. *
  433. * @sw_context: The software context used for this command submission batch.
  434. * @bo: The buffer object to add.
  435. * @validate_as_mob: Validate this buffer as a MOB.
  436. * @p_val_node: If non-NULL Will be updated with the validate node number
  437. * on return.
  438. *
  439. * Returns -EINVAL if the limit of number of buffer objects per command
  440. * submission is reached.
  441. */
  442. static int vmw_bo_to_validate_list(struct vmw_sw_context *sw_context,
  443. struct vmw_dma_buffer *vbo,
  444. bool validate_as_mob,
  445. uint32_t *p_val_node)
  446. {
  447. uint32_t val_node;
  448. struct vmw_validate_buffer *vval_buf;
  449. struct ttm_validate_buffer *val_buf;
  450. struct drm_hash_item *hash;
  451. int ret;
  452. if (likely(drm_ht_find_item(&sw_context->res_ht, (unsigned long) vbo,
  453. &hash) == 0)) {
  454. vval_buf = container_of(hash, struct vmw_validate_buffer,
  455. hash);
  456. if (unlikely(vval_buf->validate_as_mob != validate_as_mob)) {
  457. DRM_ERROR("Inconsistent buffer usage.\n");
  458. return -EINVAL;
  459. }
  460. val_buf = &vval_buf->base;
  461. val_node = vval_buf - sw_context->val_bufs;
  462. } else {
  463. val_node = sw_context->cur_val_buf;
  464. if (unlikely(val_node >= VMWGFX_MAX_VALIDATIONS)) {
  465. DRM_ERROR("Max number of DMA buffers per submission "
  466. "exceeded.\n");
  467. return -EINVAL;
  468. }
  469. vval_buf = &sw_context->val_bufs[val_node];
  470. vval_buf->hash.key = (unsigned long) vbo;
  471. ret = drm_ht_insert_item(&sw_context->res_ht, &vval_buf->hash);
  472. if (unlikely(ret != 0)) {
  473. DRM_ERROR("Failed to initialize a buffer validation "
  474. "entry.\n");
  475. return ret;
  476. }
  477. ++sw_context->cur_val_buf;
  478. val_buf = &vval_buf->base;
  479. val_buf->bo = ttm_bo_reference(&vbo->base);
  480. val_buf->shared = false;
  481. list_add_tail(&val_buf->head, &sw_context->validate_nodes);
  482. vval_buf->validate_as_mob = validate_as_mob;
  483. }
  484. if (p_val_node)
  485. *p_val_node = val_node;
  486. return 0;
  487. }
  488. /**
  489. * vmw_resources_reserve - Reserve all resources on the sw_context's
  490. * resource list.
  491. *
  492. * @sw_context: Pointer to the software context.
  493. *
  494. * Note that since vmware's command submission currently is protected by
  495. * the cmdbuf mutex, no fancy deadlock avoidance is required for resources,
  496. * since only a single thread at once will attempt this.
  497. */
  498. static int vmw_resources_reserve(struct vmw_sw_context *sw_context)
  499. {
  500. struct vmw_resource_val_node *val;
  501. int ret = 0;
  502. list_for_each_entry(val, &sw_context->resource_list, head) {
  503. struct vmw_resource *res = val->res;
  504. ret = vmw_resource_reserve(res, true, val->no_buffer_needed);
  505. if (unlikely(ret != 0))
  506. return ret;
  507. if (res->backup) {
  508. struct vmw_dma_buffer *vbo = res->backup;
  509. ret = vmw_bo_to_validate_list
  510. (sw_context, vbo,
  511. vmw_resource_needs_backup(res), NULL);
  512. if (unlikely(ret != 0))
  513. return ret;
  514. }
  515. }
  516. if (sw_context->dx_query_mob) {
  517. struct vmw_dma_buffer *expected_dx_query_mob;
  518. expected_dx_query_mob =
  519. vmw_context_get_dx_query_mob(sw_context->dx_query_ctx);
  520. if (expected_dx_query_mob &&
  521. expected_dx_query_mob != sw_context->dx_query_mob) {
  522. ret = -EINVAL;
  523. }
  524. }
  525. return ret;
  526. }
  527. /**
  528. * vmw_resources_validate - Validate all resources on the sw_context's
  529. * resource list.
  530. *
  531. * @sw_context: Pointer to the software context.
  532. *
  533. * Before this function is called, all resource backup buffers must have
  534. * been validated.
  535. */
  536. static int vmw_resources_validate(struct vmw_sw_context *sw_context)
  537. {
  538. struct vmw_resource_val_node *val;
  539. int ret;
  540. list_for_each_entry(val, &sw_context->resource_list, head) {
  541. struct vmw_resource *res = val->res;
  542. struct vmw_dma_buffer *backup = res->backup;
  543. ret = vmw_resource_validate(res);
  544. if (unlikely(ret != 0)) {
  545. if (ret != -ERESTARTSYS)
  546. DRM_ERROR("Failed to validate resource.\n");
  547. return ret;
  548. }
  549. /* Check if the resource switched backup buffer */
  550. if (backup && res->backup && (backup != res->backup)) {
  551. struct vmw_dma_buffer *vbo = res->backup;
  552. ret = vmw_bo_to_validate_list
  553. (sw_context, vbo,
  554. vmw_resource_needs_backup(res), NULL);
  555. if (ret) {
  556. ttm_bo_unreserve(&vbo->base);
  557. return ret;
  558. }
  559. }
  560. }
  561. return 0;
  562. }
  563. /**
  564. * vmw_cmd_res_reloc_add - Add a resource to a software context's
  565. * relocation- and validation lists.
  566. *
  567. * @dev_priv: Pointer to a struct vmw_private identifying the device.
  568. * @sw_context: Pointer to the software context.
  569. * @id_loc: Pointer to where the id that needs translation is located.
  570. * @res: Valid pointer to a struct vmw_resource.
  571. * @p_val: If non null, a pointer to the struct vmw_resource_validate_node
  572. * used for this resource is returned here.
  573. */
  574. static int vmw_cmd_res_reloc_add(struct vmw_private *dev_priv,
  575. struct vmw_sw_context *sw_context,
  576. uint32_t *id_loc,
  577. struct vmw_resource *res,
  578. struct vmw_resource_val_node **p_val)
  579. {
  580. int ret;
  581. struct vmw_resource_val_node *node;
  582. *p_val = NULL;
  583. ret = vmw_resource_relocation_add(&sw_context->res_relocations,
  584. res,
  585. id_loc - sw_context->buf_start);
  586. if (unlikely(ret != 0))
  587. return ret;
  588. ret = vmw_resource_val_add(sw_context, res, &node);
  589. if (unlikely(ret != 0))
  590. return ret;
  591. if (p_val)
  592. *p_val = node;
  593. return 0;
  594. }
  595. /**
  596. * vmw_cmd_res_check - Check that a resource is present and if so, put it
  597. * on the resource validate list unless it's already there.
  598. *
  599. * @dev_priv: Pointer to a device private structure.
  600. * @sw_context: Pointer to the software context.
  601. * @res_type: Resource type.
  602. * @converter: User-space visisble type specific information.
  603. * @id_loc: Pointer to the location in the command buffer currently being
  604. * parsed from where the user-space resource id handle is located.
  605. * @p_val: Pointer to pointer to resource validalidation node. Populated
  606. * on exit.
  607. */
  608. static int
  609. vmw_cmd_res_check(struct vmw_private *dev_priv,
  610. struct vmw_sw_context *sw_context,
  611. enum vmw_res_type res_type,
  612. const struct vmw_user_resource_conv *converter,
  613. uint32_t *id_loc,
  614. struct vmw_resource_val_node **p_val)
  615. {
  616. struct vmw_res_cache_entry *rcache =
  617. &sw_context->res_cache[res_type];
  618. struct vmw_resource *res;
  619. struct vmw_resource_val_node *node;
  620. int ret;
  621. if (*id_loc == SVGA3D_INVALID_ID) {
  622. if (p_val)
  623. *p_val = NULL;
  624. if (res_type == vmw_res_context) {
  625. DRM_ERROR("Illegal context invalid id.\n");
  626. return -EINVAL;
  627. }
  628. return 0;
  629. }
  630. /*
  631. * Fastpath in case of repeated commands referencing the same
  632. * resource
  633. */
  634. if (likely(rcache->valid && *id_loc == rcache->handle)) {
  635. const struct vmw_resource *res = rcache->res;
  636. rcache->node->first_usage = false;
  637. if (p_val)
  638. *p_val = rcache->node;
  639. return vmw_resource_relocation_add
  640. (&sw_context->res_relocations, res,
  641. id_loc - sw_context->buf_start);
  642. }
  643. ret = vmw_user_resource_lookup_handle(dev_priv,
  644. sw_context->fp->tfile,
  645. *id_loc,
  646. converter,
  647. &res);
  648. if (unlikely(ret != 0)) {
  649. DRM_ERROR("Could not find or use resource 0x%08x.\n",
  650. (unsigned) *id_loc);
  651. dump_stack();
  652. return ret;
  653. }
  654. rcache->valid = true;
  655. rcache->res = res;
  656. rcache->handle = *id_loc;
  657. ret = vmw_cmd_res_reloc_add(dev_priv, sw_context, id_loc,
  658. res, &node);
  659. if (unlikely(ret != 0))
  660. goto out_no_reloc;
  661. rcache->node = node;
  662. if (p_val)
  663. *p_val = node;
  664. vmw_resource_unreference(&res);
  665. return 0;
  666. out_no_reloc:
  667. BUG_ON(sw_context->error_resource != NULL);
  668. sw_context->error_resource = res;
  669. return ret;
  670. }
  671. /**
  672. * vmw_rebind_dx_query - Rebind DX query associated with the context
  673. *
  674. * @ctx_res: context the query belongs to
  675. *
  676. * This function assumes binding_mutex is held.
  677. */
  678. static int vmw_rebind_all_dx_query(struct vmw_resource *ctx_res)
  679. {
  680. struct vmw_private *dev_priv = ctx_res->dev_priv;
  681. struct vmw_dma_buffer *dx_query_mob;
  682. struct {
  683. SVGA3dCmdHeader header;
  684. SVGA3dCmdDXBindAllQuery body;
  685. } *cmd;
  686. dx_query_mob = vmw_context_get_dx_query_mob(ctx_res);
  687. if (!dx_query_mob || dx_query_mob->dx_query_ctx)
  688. return 0;
  689. cmd = vmw_fifo_reserve_dx(dev_priv, sizeof(*cmd), ctx_res->id);
  690. if (cmd == NULL) {
  691. DRM_ERROR("Failed to rebind queries.\n");
  692. return -ENOMEM;
  693. }
  694. cmd->header.id = SVGA_3D_CMD_DX_BIND_ALL_QUERY;
  695. cmd->header.size = sizeof(cmd->body);
  696. cmd->body.cid = ctx_res->id;
  697. cmd->body.mobid = dx_query_mob->base.mem.start;
  698. vmw_fifo_commit(dev_priv, sizeof(*cmd));
  699. vmw_context_bind_dx_query(ctx_res, dx_query_mob);
  700. return 0;
  701. }
  702. /**
  703. * vmw_rebind_contexts - Rebind all resources previously bound to
  704. * referenced contexts.
  705. *
  706. * @sw_context: Pointer to the software context.
  707. *
  708. * Rebind context binding points that have been scrubbed because of eviction.
  709. */
  710. static int vmw_rebind_contexts(struct vmw_sw_context *sw_context)
  711. {
  712. struct vmw_resource_val_node *val;
  713. int ret;
  714. list_for_each_entry(val, &sw_context->resource_list, head) {
  715. if (unlikely(!val->staged_bindings))
  716. break;
  717. ret = vmw_binding_rebind_all
  718. (vmw_context_binding_state(val->res));
  719. if (unlikely(ret != 0)) {
  720. if (ret != -ERESTARTSYS)
  721. DRM_ERROR("Failed to rebind context.\n");
  722. return ret;
  723. }
  724. ret = vmw_rebind_all_dx_query(val->res);
  725. if (ret != 0)
  726. return ret;
  727. }
  728. return 0;
  729. }
  730. /**
  731. * vmw_view_bindings_add - Add an array of view bindings to a context
  732. * binding state tracker.
  733. *
  734. * @sw_context: The execbuf state used for this command.
  735. * @view_type: View type for the bindings.
  736. * @binding_type: Binding type for the bindings.
  737. * @shader_slot: The shader slot to user for the bindings.
  738. * @view_ids: Array of view ids to be bound.
  739. * @num_views: Number of view ids in @view_ids.
  740. * @first_slot: The binding slot to be used for the first view id in @view_ids.
  741. */
  742. static int vmw_view_bindings_add(struct vmw_sw_context *sw_context,
  743. enum vmw_view_type view_type,
  744. enum vmw_ctx_binding_type binding_type,
  745. uint32 shader_slot,
  746. uint32 view_ids[], u32 num_views,
  747. u32 first_slot)
  748. {
  749. struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
  750. struct vmw_cmdbuf_res_manager *man;
  751. u32 i;
  752. int ret;
  753. if (!ctx_node) {
  754. DRM_ERROR("DX Context not set.\n");
  755. return -EINVAL;
  756. }
  757. man = sw_context->man;
  758. for (i = 0; i < num_views; ++i) {
  759. struct vmw_ctx_bindinfo_view binding;
  760. struct vmw_resource *view = NULL;
  761. if (view_ids[i] != SVGA3D_INVALID_ID) {
  762. view = vmw_view_lookup(man, view_type, view_ids[i]);
  763. if (IS_ERR(view)) {
  764. DRM_ERROR("View not found.\n");
  765. return PTR_ERR(view);
  766. }
  767. ret = vmw_view_res_val_add(sw_context, view);
  768. if (ret) {
  769. DRM_ERROR("Could not add view to "
  770. "validation list.\n");
  771. vmw_resource_unreference(&view);
  772. return ret;
  773. }
  774. }
  775. binding.bi.ctx = ctx_node->res;
  776. binding.bi.res = view;
  777. binding.bi.bt = binding_type;
  778. binding.shader_slot = shader_slot;
  779. binding.slot = first_slot + i;
  780. vmw_binding_add(ctx_node->staged_bindings, &binding.bi,
  781. shader_slot, binding.slot);
  782. if (view)
  783. vmw_resource_unreference(&view);
  784. }
  785. return 0;
  786. }
  787. /**
  788. * vmw_cmd_cid_check - Check a command header for valid context information.
  789. *
  790. * @dev_priv: Pointer to a device private structure.
  791. * @sw_context: Pointer to the software context.
  792. * @header: A command header with an embedded user-space context handle.
  793. *
  794. * Convenience function: Call vmw_cmd_res_check with the user-space context
  795. * handle embedded in @header.
  796. */
  797. static int vmw_cmd_cid_check(struct vmw_private *dev_priv,
  798. struct vmw_sw_context *sw_context,
  799. SVGA3dCmdHeader *header)
  800. {
  801. struct vmw_cid_cmd {
  802. SVGA3dCmdHeader header;
  803. uint32_t cid;
  804. } *cmd;
  805. cmd = container_of(header, struct vmw_cid_cmd, header);
  806. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
  807. user_context_converter, &cmd->cid, NULL);
  808. }
  809. static int vmw_cmd_set_render_target_check(struct vmw_private *dev_priv,
  810. struct vmw_sw_context *sw_context,
  811. SVGA3dCmdHeader *header)
  812. {
  813. struct vmw_sid_cmd {
  814. SVGA3dCmdHeader header;
  815. SVGA3dCmdSetRenderTarget body;
  816. } *cmd;
  817. struct vmw_resource_val_node *ctx_node;
  818. struct vmw_resource_val_node *res_node;
  819. int ret;
  820. cmd = container_of(header, struct vmw_sid_cmd, header);
  821. if (cmd->body.type >= SVGA3D_RT_MAX) {
  822. DRM_ERROR("Illegal render target type %u.\n",
  823. (unsigned) cmd->body.type);
  824. return -EINVAL;
  825. }
  826. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
  827. user_context_converter, &cmd->body.cid,
  828. &ctx_node);
  829. if (unlikely(ret != 0))
  830. return ret;
  831. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  832. user_surface_converter,
  833. &cmd->body.target.sid, &res_node);
  834. if (unlikely(ret != 0))
  835. return ret;
  836. if (dev_priv->has_mob) {
  837. struct vmw_ctx_bindinfo_view binding;
  838. binding.bi.ctx = ctx_node->res;
  839. binding.bi.res = res_node ? res_node->res : NULL;
  840. binding.bi.bt = vmw_ctx_binding_rt;
  841. binding.slot = cmd->body.type;
  842. vmw_binding_add(ctx_node->staged_bindings,
  843. &binding.bi, 0, binding.slot);
  844. }
  845. return 0;
  846. }
  847. static int vmw_cmd_surface_copy_check(struct vmw_private *dev_priv,
  848. struct vmw_sw_context *sw_context,
  849. SVGA3dCmdHeader *header)
  850. {
  851. struct vmw_sid_cmd {
  852. SVGA3dCmdHeader header;
  853. SVGA3dCmdSurfaceCopy body;
  854. } *cmd;
  855. int ret;
  856. cmd = container_of(header, struct vmw_sid_cmd, header);
  857. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  858. user_surface_converter,
  859. &cmd->body.src.sid, NULL);
  860. if (ret)
  861. return ret;
  862. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  863. user_surface_converter,
  864. &cmd->body.dest.sid, NULL);
  865. }
  866. static int vmw_cmd_buffer_copy_check(struct vmw_private *dev_priv,
  867. struct vmw_sw_context *sw_context,
  868. SVGA3dCmdHeader *header)
  869. {
  870. struct {
  871. SVGA3dCmdHeader header;
  872. SVGA3dCmdDXBufferCopy body;
  873. } *cmd;
  874. int ret;
  875. cmd = container_of(header, typeof(*cmd), header);
  876. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  877. user_surface_converter,
  878. &cmd->body.src, NULL);
  879. if (ret != 0)
  880. return ret;
  881. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  882. user_surface_converter,
  883. &cmd->body.dest, NULL);
  884. }
  885. static int vmw_cmd_pred_copy_check(struct vmw_private *dev_priv,
  886. struct vmw_sw_context *sw_context,
  887. SVGA3dCmdHeader *header)
  888. {
  889. struct {
  890. SVGA3dCmdHeader header;
  891. SVGA3dCmdDXPredCopyRegion body;
  892. } *cmd;
  893. int ret;
  894. cmd = container_of(header, typeof(*cmd), header);
  895. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  896. user_surface_converter,
  897. &cmd->body.srcSid, NULL);
  898. if (ret != 0)
  899. return ret;
  900. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  901. user_surface_converter,
  902. &cmd->body.dstSid, NULL);
  903. }
  904. static int vmw_cmd_stretch_blt_check(struct vmw_private *dev_priv,
  905. struct vmw_sw_context *sw_context,
  906. SVGA3dCmdHeader *header)
  907. {
  908. struct vmw_sid_cmd {
  909. SVGA3dCmdHeader header;
  910. SVGA3dCmdSurfaceStretchBlt body;
  911. } *cmd;
  912. int ret;
  913. cmd = container_of(header, struct vmw_sid_cmd, header);
  914. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  915. user_surface_converter,
  916. &cmd->body.src.sid, NULL);
  917. if (unlikely(ret != 0))
  918. return ret;
  919. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  920. user_surface_converter,
  921. &cmd->body.dest.sid, NULL);
  922. }
  923. static int vmw_cmd_blt_surf_screen_check(struct vmw_private *dev_priv,
  924. struct vmw_sw_context *sw_context,
  925. SVGA3dCmdHeader *header)
  926. {
  927. struct vmw_sid_cmd {
  928. SVGA3dCmdHeader header;
  929. SVGA3dCmdBlitSurfaceToScreen body;
  930. } *cmd;
  931. cmd = container_of(header, struct vmw_sid_cmd, header);
  932. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  933. user_surface_converter,
  934. &cmd->body.srcImage.sid, NULL);
  935. }
  936. static int vmw_cmd_present_check(struct vmw_private *dev_priv,
  937. struct vmw_sw_context *sw_context,
  938. SVGA3dCmdHeader *header)
  939. {
  940. struct vmw_sid_cmd {
  941. SVGA3dCmdHeader header;
  942. SVGA3dCmdPresent body;
  943. } *cmd;
  944. cmd = container_of(header, struct vmw_sid_cmd, header);
  945. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  946. user_surface_converter, &cmd->body.sid,
  947. NULL);
  948. }
  949. /**
  950. * vmw_query_bo_switch_prepare - Prepare to switch pinned buffer for queries.
  951. *
  952. * @dev_priv: The device private structure.
  953. * @new_query_bo: The new buffer holding query results.
  954. * @sw_context: The software context used for this command submission.
  955. *
  956. * This function checks whether @new_query_bo is suitable for holding
  957. * query results, and if another buffer currently is pinned for query
  958. * results. If so, the function prepares the state of @sw_context for
  959. * switching pinned buffers after successful submission of the current
  960. * command batch.
  961. */
  962. static int vmw_query_bo_switch_prepare(struct vmw_private *dev_priv,
  963. struct vmw_dma_buffer *new_query_bo,
  964. struct vmw_sw_context *sw_context)
  965. {
  966. struct vmw_res_cache_entry *ctx_entry =
  967. &sw_context->res_cache[vmw_res_context];
  968. int ret;
  969. BUG_ON(!ctx_entry->valid);
  970. sw_context->last_query_ctx = ctx_entry->res;
  971. if (unlikely(new_query_bo != sw_context->cur_query_bo)) {
  972. if (unlikely(new_query_bo->base.num_pages > 4)) {
  973. DRM_ERROR("Query buffer too large.\n");
  974. return -EINVAL;
  975. }
  976. if (unlikely(sw_context->cur_query_bo != NULL)) {
  977. sw_context->needs_post_query_barrier = true;
  978. ret = vmw_bo_to_validate_list(sw_context,
  979. sw_context->cur_query_bo,
  980. dev_priv->has_mob, NULL);
  981. if (unlikely(ret != 0))
  982. return ret;
  983. }
  984. sw_context->cur_query_bo = new_query_bo;
  985. ret = vmw_bo_to_validate_list(sw_context,
  986. dev_priv->dummy_query_bo,
  987. dev_priv->has_mob, NULL);
  988. if (unlikely(ret != 0))
  989. return ret;
  990. }
  991. return 0;
  992. }
  993. /**
  994. * vmw_query_bo_switch_commit - Finalize switching pinned query buffer
  995. *
  996. * @dev_priv: The device private structure.
  997. * @sw_context: The software context used for this command submission batch.
  998. *
  999. * This function will check if we're switching query buffers, and will then,
  1000. * issue a dummy occlusion query wait used as a query barrier. When the fence
  1001. * object following that query wait has signaled, we are sure that all
  1002. * preceding queries have finished, and the old query buffer can be unpinned.
  1003. * However, since both the new query buffer and the old one are fenced with
  1004. * that fence, we can do an asynchronus unpin now, and be sure that the
  1005. * old query buffer won't be moved until the fence has signaled.
  1006. *
  1007. * As mentioned above, both the new - and old query buffers need to be fenced
  1008. * using a sequence emitted *after* calling this function.
  1009. */
  1010. static void vmw_query_bo_switch_commit(struct vmw_private *dev_priv,
  1011. struct vmw_sw_context *sw_context)
  1012. {
  1013. /*
  1014. * The validate list should still hold references to all
  1015. * contexts here.
  1016. */
  1017. if (sw_context->needs_post_query_barrier) {
  1018. struct vmw_res_cache_entry *ctx_entry =
  1019. &sw_context->res_cache[vmw_res_context];
  1020. struct vmw_resource *ctx;
  1021. int ret;
  1022. BUG_ON(!ctx_entry->valid);
  1023. ctx = ctx_entry->res;
  1024. ret = vmw_fifo_emit_dummy_query(dev_priv, ctx->id);
  1025. if (unlikely(ret != 0))
  1026. DRM_ERROR("Out of fifo space for dummy query.\n");
  1027. }
  1028. if (dev_priv->pinned_bo != sw_context->cur_query_bo) {
  1029. if (dev_priv->pinned_bo) {
  1030. vmw_bo_pin_reserved(dev_priv->pinned_bo, false);
  1031. vmw_dmabuf_unreference(&dev_priv->pinned_bo);
  1032. }
  1033. if (!sw_context->needs_post_query_barrier) {
  1034. vmw_bo_pin_reserved(sw_context->cur_query_bo, true);
  1035. /*
  1036. * We pin also the dummy_query_bo buffer so that we
  1037. * don't need to validate it when emitting
  1038. * dummy queries in context destroy paths.
  1039. */
  1040. if (!dev_priv->dummy_query_bo_pinned) {
  1041. vmw_bo_pin_reserved(dev_priv->dummy_query_bo,
  1042. true);
  1043. dev_priv->dummy_query_bo_pinned = true;
  1044. }
  1045. BUG_ON(sw_context->last_query_ctx == NULL);
  1046. dev_priv->query_cid = sw_context->last_query_ctx->id;
  1047. dev_priv->query_cid_valid = true;
  1048. dev_priv->pinned_bo =
  1049. vmw_dmabuf_reference(sw_context->cur_query_bo);
  1050. }
  1051. }
  1052. }
  1053. /**
  1054. * vmw_translate_mob_pointer - Prepare to translate a user-space buffer
  1055. * handle to a MOB id.
  1056. *
  1057. * @dev_priv: Pointer to a device private structure.
  1058. * @sw_context: The software context used for this command batch validation.
  1059. * @id: Pointer to the user-space handle to be translated.
  1060. * @vmw_bo_p: Points to a location that, on successful return will carry
  1061. * a reference-counted pointer to the DMA buffer identified by the
  1062. * user-space handle in @id.
  1063. *
  1064. * This function saves information needed to translate a user-space buffer
  1065. * handle to a MOB id. The translation does not take place immediately, but
  1066. * during a call to vmw_apply_relocations(). This function builds a relocation
  1067. * list and a list of buffers to validate. The former needs to be freed using
  1068. * either vmw_apply_relocations() or vmw_free_relocations(). The latter
  1069. * needs to be freed using vmw_clear_validations.
  1070. */
  1071. static int vmw_translate_mob_ptr(struct vmw_private *dev_priv,
  1072. struct vmw_sw_context *sw_context,
  1073. SVGAMobId *id,
  1074. struct vmw_dma_buffer **vmw_bo_p)
  1075. {
  1076. struct vmw_dma_buffer *vmw_bo = NULL;
  1077. uint32_t handle = *id;
  1078. struct vmw_relocation *reloc;
  1079. int ret;
  1080. ret = vmw_user_dmabuf_lookup(sw_context->fp->tfile, handle, &vmw_bo,
  1081. NULL);
  1082. if (unlikely(ret != 0)) {
  1083. DRM_ERROR("Could not find or use MOB buffer.\n");
  1084. ret = -EINVAL;
  1085. goto out_no_reloc;
  1086. }
  1087. if (unlikely(sw_context->cur_reloc >= VMWGFX_MAX_RELOCATIONS)) {
  1088. DRM_ERROR("Max number relocations per submission"
  1089. " exceeded\n");
  1090. ret = -EINVAL;
  1091. goto out_no_reloc;
  1092. }
  1093. reloc = &sw_context->relocs[sw_context->cur_reloc++];
  1094. reloc->mob_loc = id;
  1095. reloc->location = NULL;
  1096. ret = vmw_bo_to_validate_list(sw_context, vmw_bo, true, &reloc->index);
  1097. if (unlikely(ret != 0))
  1098. goto out_no_reloc;
  1099. *vmw_bo_p = vmw_bo;
  1100. return 0;
  1101. out_no_reloc:
  1102. vmw_dmabuf_unreference(&vmw_bo);
  1103. *vmw_bo_p = NULL;
  1104. return ret;
  1105. }
  1106. /**
  1107. * vmw_translate_guest_pointer - Prepare to translate a user-space buffer
  1108. * handle to a valid SVGAGuestPtr
  1109. *
  1110. * @dev_priv: Pointer to a device private structure.
  1111. * @sw_context: The software context used for this command batch validation.
  1112. * @ptr: Pointer to the user-space handle to be translated.
  1113. * @vmw_bo_p: Points to a location that, on successful return will carry
  1114. * a reference-counted pointer to the DMA buffer identified by the
  1115. * user-space handle in @id.
  1116. *
  1117. * This function saves information needed to translate a user-space buffer
  1118. * handle to a valid SVGAGuestPtr. The translation does not take place
  1119. * immediately, but during a call to vmw_apply_relocations().
  1120. * This function builds a relocation list and a list of buffers to validate.
  1121. * The former needs to be freed using either vmw_apply_relocations() or
  1122. * vmw_free_relocations(). The latter needs to be freed using
  1123. * vmw_clear_validations.
  1124. */
  1125. static int vmw_translate_guest_ptr(struct vmw_private *dev_priv,
  1126. struct vmw_sw_context *sw_context,
  1127. SVGAGuestPtr *ptr,
  1128. struct vmw_dma_buffer **vmw_bo_p)
  1129. {
  1130. struct vmw_dma_buffer *vmw_bo = NULL;
  1131. uint32_t handle = ptr->gmrId;
  1132. struct vmw_relocation *reloc;
  1133. int ret;
  1134. ret = vmw_user_dmabuf_lookup(sw_context->fp->tfile, handle, &vmw_bo,
  1135. NULL);
  1136. if (unlikely(ret != 0)) {
  1137. DRM_ERROR("Could not find or use GMR region.\n");
  1138. ret = -EINVAL;
  1139. goto out_no_reloc;
  1140. }
  1141. if (unlikely(sw_context->cur_reloc >= VMWGFX_MAX_RELOCATIONS)) {
  1142. DRM_ERROR("Max number relocations per submission"
  1143. " exceeded\n");
  1144. ret = -EINVAL;
  1145. goto out_no_reloc;
  1146. }
  1147. reloc = &sw_context->relocs[sw_context->cur_reloc++];
  1148. reloc->location = ptr;
  1149. ret = vmw_bo_to_validate_list(sw_context, vmw_bo, false, &reloc->index);
  1150. if (unlikely(ret != 0))
  1151. goto out_no_reloc;
  1152. *vmw_bo_p = vmw_bo;
  1153. return 0;
  1154. out_no_reloc:
  1155. vmw_dmabuf_unreference(&vmw_bo);
  1156. *vmw_bo_p = NULL;
  1157. return ret;
  1158. }
  1159. /**
  1160. * vmw_cmd_dx_define_query - validate a SVGA_3D_CMD_DX_DEFINE_QUERY command.
  1161. *
  1162. * @dev_priv: Pointer to a device private struct.
  1163. * @sw_context: The software context used for this command submission.
  1164. * @header: Pointer to the command header in the command stream.
  1165. *
  1166. * This function adds the new query into the query COTABLE
  1167. */
  1168. static int vmw_cmd_dx_define_query(struct vmw_private *dev_priv,
  1169. struct vmw_sw_context *sw_context,
  1170. SVGA3dCmdHeader *header)
  1171. {
  1172. struct vmw_dx_define_query_cmd {
  1173. SVGA3dCmdHeader header;
  1174. SVGA3dCmdDXDefineQuery q;
  1175. } *cmd;
  1176. int ret;
  1177. struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
  1178. struct vmw_resource *cotable_res;
  1179. if (ctx_node == NULL) {
  1180. DRM_ERROR("DX Context not set for query.\n");
  1181. return -EINVAL;
  1182. }
  1183. cmd = container_of(header, struct vmw_dx_define_query_cmd, header);
  1184. if (cmd->q.type < SVGA3D_QUERYTYPE_MIN ||
  1185. cmd->q.type >= SVGA3D_QUERYTYPE_MAX)
  1186. return -EINVAL;
  1187. cotable_res = vmw_context_cotable(ctx_node->res, SVGA_COTABLE_DXQUERY);
  1188. ret = vmw_cotable_notify(cotable_res, cmd->q.queryId);
  1189. vmw_resource_unreference(&cotable_res);
  1190. return ret;
  1191. }
  1192. /**
  1193. * vmw_cmd_dx_bind_query - validate a SVGA_3D_CMD_DX_BIND_QUERY command.
  1194. *
  1195. * @dev_priv: Pointer to a device private struct.
  1196. * @sw_context: The software context used for this command submission.
  1197. * @header: Pointer to the command header in the command stream.
  1198. *
  1199. * The query bind operation will eventually associate the query ID
  1200. * with its backing MOB. In this function, we take the user mode
  1201. * MOB ID and use vmw_translate_mob_ptr() to translate it to its
  1202. * kernel mode equivalent.
  1203. */
  1204. static int vmw_cmd_dx_bind_query(struct vmw_private *dev_priv,
  1205. struct vmw_sw_context *sw_context,
  1206. SVGA3dCmdHeader *header)
  1207. {
  1208. struct vmw_dx_bind_query_cmd {
  1209. SVGA3dCmdHeader header;
  1210. SVGA3dCmdDXBindQuery q;
  1211. } *cmd;
  1212. struct vmw_dma_buffer *vmw_bo;
  1213. int ret;
  1214. cmd = container_of(header, struct vmw_dx_bind_query_cmd, header);
  1215. /*
  1216. * Look up the buffer pointed to by q.mobid, put it on the relocation
  1217. * list so its kernel mode MOB ID can be filled in later
  1218. */
  1219. ret = vmw_translate_mob_ptr(dev_priv, sw_context, &cmd->q.mobid,
  1220. &vmw_bo);
  1221. if (ret != 0)
  1222. return ret;
  1223. sw_context->dx_query_mob = vmw_bo;
  1224. sw_context->dx_query_ctx = sw_context->dx_ctx_node->res;
  1225. vmw_dmabuf_unreference(&vmw_bo);
  1226. return ret;
  1227. }
  1228. /**
  1229. * vmw_cmd_begin_gb_query - validate a SVGA_3D_CMD_BEGIN_GB_QUERY command.
  1230. *
  1231. * @dev_priv: Pointer to a device private struct.
  1232. * @sw_context: The software context used for this command submission.
  1233. * @header: Pointer to the command header in the command stream.
  1234. */
  1235. static int vmw_cmd_begin_gb_query(struct vmw_private *dev_priv,
  1236. struct vmw_sw_context *sw_context,
  1237. SVGA3dCmdHeader *header)
  1238. {
  1239. struct vmw_begin_gb_query_cmd {
  1240. SVGA3dCmdHeader header;
  1241. SVGA3dCmdBeginGBQuery q;
  1242. } *cmd;
  1243. cmd = container_of(header, struct vmw_begin_gb_query_cmd,
  1244. header);
  1245. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
  1246. user_context_converter, &cmd->q.cid,
  1247. NULL);
  1248. }
  1249. /**
  1250. * vmw_cmd_begin_query - validate a SVGA_3D_CMD_BEGIN_QUERY command.
  1251. *
  1252. * @dev_priv: Pointer to a device private struct.
  1253. * @sw_context: The software context used for this command submission.
  1254. * @header: Pointer to the command header in the command stream.
  1255. */
  1256. static int vmw_cmd_begin_query(struct vmw_private *dev_priv,
  1257. struct vmw_sw_context *sw_context,
  1258. SVGA3dCmdHeader *header)
  1259. {
  1260. struct vmw_begin_query_cmd {
  1261. SVGA3dCmdHeader header;
  1262. SVGA3dCmdBeginQuery q;
  1263. } *cmd;
  1264. cmd = container_of(header, struct vmw_begin_query_cmd,
  1265. header);
  1266. if (unlikely(dev_priv->has_mob)) {
  1267. struct {
  1268. SVGA3dCmdHeader header;
  1269. SVGA3dCmdBeginGBQuery q;
  1270. } gb_cmd;
  1271. BUG_ON(sizeof(gb_cmd) != sizeof(*cmd));
  1272. gb_cmd.header.id = SVGA_3D_CMD_BEGIN_GB_QUERY;
  1273. gb_cmd.header.size = cmd->header.size;
  1274. gb_cmd.q.cid = cmd->q.cid;
  1275. gb_cmd.q.type = cmd->q.type;
  1276. memcpy(cmd, &gb_cmd, sizeof(*cmd));
  1277. return vmw_cmd_begin_gb_query(dev_priv, sw_context, header);
  1278. }
  1279. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
  1280. user_context_converter, &cmd->q.cid,
  1281. NULL);
  1282. }
  1283. /**
  1284. * vmw_cmd_end_gb_query - validate a SVGA_3D_CMD_END_GB_QUERY command.
  1285. *
  1286. * @dev_priv: Pointer to a device private struct.
  1287. * @sw_context: The software context used for this command submission.
  1288. * @header: Pointer to the command header in the command stream.
  1289. */
  1290. static int vmw_cmd_end_gb_query(struct vmw_private *dev_priv,
  1291. struct vmw_sw_context *sw_context,
  1292. SVGA3dCmdHeader *header)
  1293. {
  1294. struct vmw_dma_buffer *vmw_bo;
  1295. struct vmw_query_cmd {
  1296. SVGA3dCmdHeader header;
  1297. SVGA3dCmdEndGBQuery q;
  1298. } *cmd;
  1299. int ret;
  1300. cmd = container_of(header, struct vmw_query_cmd, header);
  1301. ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
  1302. if (unlikely(ret != 0))
  1303. return ret;
  1304. ret = vmw_translate_mob_ptr(dev_priv, sw_context,
  1305. &cmd->q.mobid,
  1306. &vmw_bo);
  1307. if (unlikely(ret != 0))
  1308. return ret;
  1309. ret = vmw_query_bo_switch_prepare(dev_priv, vmw_bo, sw_context);
  1310. vmw_dmabuf_unreference(&vmw_bo);
  1311. return ret;
  1312. }
  1313. /**
  1314. * vmw_cmd_end_query - validate a SVGA_3D_CMD_END_QUERY command.
  1315. *
  1316. * @dev_priv: Pointer to a device private struct.
  1317. * @sw_context: The software context used for this command submission.
  1318. * @header: Pointer to the command header in the command stream.
  1319. */
  1320. static int vmw_cmd_end_query(struct vmw_private *dev_priv,
  1321. struct vmw_sw_context *sw_context,
  1322. SVGA3dCmdHeader *header)
  1323. {
  1324. struct vmw_dma_buffer *vmw_bo;
  1325. struct vmw_query_cmd {
  1326. SVGA3dCmdHeader header;
  1327. SVGA3dCmdEndQuery q;
  1328. } *cmd;
  1329. int ret;
  1330. cmd = container_of(header, struct vmw_query_cmd, header);
  1331. if (dev_priv->has_mob) {
  1332. struct {
  1333. SVGA3dCmdHeader header;
  1334. SVGA3dCmdEndGBQuery q;
  1335. } gb_cmd;
  1336. BUG_ON(sizeof(gb_cmd) != sizeof(*cmd));
  1337. gb_cmd.header.id = SVGA_3D_CMD_END_GB_QUERY;
  1338. gb_cmd.header.size = cmd->header.size;
  1339. gb_cmd.q.cid = cmd->q.cid;
  1340. gb_cmd.q.type = cmd->q.type;
  1341. gb_cmd.q.mobid = cmd->q.guestResult.gmrId;
  1342. gb_cmd.q.offset = cmd->q.guestResult.offset;
  1343. memcpy(cmd, &gb_cmd, sizeof(*cmd));
  1344. return vmw_cmd_end_gb_query(dev_priv, sw_context, header);
  1345. }
  1346. ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
  1347. if (unlikely(ret != 0))
  1348. return ret;
  1349. ret = vmw_translate_guest_ptr(dev_priv, sw_context,
  1350. &cmd->q.guestResult,
  1351. &vmw_bo);
  1352. if (unlikely(ret != 0))
  1353. return ret;
  1354. ret = vmw_query_bo_switch_prepare(dev_priv, vmw_bo, sw_context);
  1355. vmw_dmabuf_unreference(&vmw_bo);
  1356. return ret;
  1357. }
  1358. /**
  1359. * vmw_cmd_wait_gb_query - validate a SVGA_3D_CMD_WAIT_GB_QUERY command.
  1360. *
  1361. * @dev_priv: Pointer to a device private struct.
  1362. * @sw_context: The software context used for this command submission.
  1363. * @header: Pointer to the command header in the command stream.
  1364. */
  1365. static int vmw_cmd_wait_gb_query(struct vmw_private *dev_priv,
  1366. struct vmw_sw_context *sw_context,
  1367. SVGA3dCmdHeader *header)
  1368. {
  1369. struct vmw_dma_buffer *vmw_bo;
  1370. struct vmw_query_cmd {
  1371. SVGA3dCmdHeader header;
  1372. SVGA3dCmdWaitForGBQuery q;
  1373. } *cmd;
  1374. int ret;
  1375. cmd = container_of(header, struct vmw_query_cmd, header);
  1376. ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
  1377. if (unlikely(ret != 0))
  1378. return ret;
  1379. ret = vmw_translate_mob_ptr(dev_priv, sw_context,
  1380. &cmd->q.mobid,
  1381. &vmw_bo);
  1382. if (unlikely(ret != 0))
  1383. return ret;
  1384. vmw_dmabuf_unreference(&vmw_bo);
  1385. return 0;
  1386. }
  1387. /**
  1388. * vmw_cmd_wait_query - validate a SVGA_3D_CMD_WAIT_QUERY command.
  1389. *
  1390. * @dev_priv: Pointer to a device private struct.
  1391. * @sw_context: The software context used for this command submission.
  1392. * @header: Pointer to the command header in the command stream.
  1393. */
  1394. static int vmw_cmd_wait_query(struct vmw_private *dev_priv,
  1395. struct vmw_sw_context *sw_context,
  1396. SVGA3dCmdHeader *header)
  1397. {
  1398. struct vmw_dma_buffer *vmw_bo;
  1399. struct vmw_query_cmd {
  1400. SVGA3dCmdHeader header;
  1401. SVGA3dCmdWaitForQuery q;
  1402. } *cmd;
  1403. int ret;
  1404. cmd = container_of(header, struct vmw_query_cmd, header);
  1405. if (dev_priv->has_mob) {
  1406. struct {
  1407. SVGA3dCmdHeader header;
  1408. SVGA3dCmdWaitForGBQuery q;
  1409. } gb_cmd;
  1410. BUG_ON(sizeof(gb_cmd) != sizeof(*cmd));
  1411. gb_cmd.header.id = SVGA_3D_CMD_WAIT_FOR_GB_QUERY;
  1412. gb_cmd.header.size = cmd->header.size;
  1413. gb_cmd.q.cid = cmd->q.cid;
  1414. gb_cmd.q.type = cmd->q.type;
  1415. gb_cmd.q.mobid = cmd->q.guestResult.gmrId;
  1416. gb_cmd.q.offset = cmd->q.guestResult.offset;
  1417. memcpy(cmd, &gb_cmd, sizeof(*cmd));
  1418. return vmw_cmd_wait_gb_query(dev_priv, sw_context, header);
  1419. }
  1420. ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
  1421. if (unlikely(ret != 0))
  1422. return ret;
  1423. ret = vmw_translate_guest_ptr(dev_priv, sw_context,
  1424. &cmd->q.guestResult,
  1425. &vmw_bo);
  1426. if (unlikely(ret != 0))
  1427. return ret;
  1428. vmw_dmabuf_unreference(&vmw_bo);
  1429. return 0;
  1430. }
  1431. static int vmw_cmd_dma(struct vmw_private *dev_priv,
  1432. struct vmw_sw_context *sw_context,
  1433. SVGA3dCmdHeader *header)
  1434. {
  1435. struct vmw_dma_buffer *vmw_bo = NULL;
  1436. struct vmw_surface *srf = NULL;
  1437. struct vmw_dma_cmd {
  1438. SVGA3dCmdHeader header;
  1439. SVGA3dCmdSurfaceDMA dma;
  1440. } *cmd;
  1441. int ret;
  1442. SVGA3dCmdSurfaceDMASuffix *suffix;
  1443. uint32_t bo_size;
  1444. cmd = container_of(header, struct vmw_dma_cmd, header);
  1445. suffix = (SVGA3dCmdSurfaceDMASuffix *)((unsigned long) &cmd->dma +
  1446. header->size - sizeof(*suffix));
  1447. /* Make sure device and verifier stays in sync. */
  1448. if (unlikely(suffix->suffixSize != sizeof(*suffix))) {
  1449. DRM_ERROR("Invalid DMA suffix size.\n");
  1450. return -EINVAL;
  1451. }
  1452. ret = vmw_translate_guest_ptr(dev_priv, sw_context,
  1453. &cmd->dma.guest.ptr,
  1454. &vmw_bo);
  1455. if (unlikely(ret != 0))
  1456. return ret;
  1457. /* Make sure DMA doesn't cross BO boundaries. */
  1458. bo_size = vmw_bo->base.num_pages * PAGE_SIZE;
  1459. if (unlikely(cmd->dma.guest.ptr.offset > bo_size)) {
  1460. DRM_ERROR("Invalid DMA offset.\n");
  1461. return -EINVAL;
  1462. }
  1463. bo_size -= cmd->dma.guest.ptr.offset;
  1464. if (unlikely(suffix->maximumOffset > bo_size))
  1465. suffix->maximumOffset = bo_size;
  1466. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  1467. user_surface_converter, &cmd->dma.host.sid,
  1468. NULL);
  1469. if (unlikely(ret != 0)) {
  1470. if (unlikely(ret != -ERESTARTSYS))
  1471. DRM_ERROR("could not find surface for DMA.\n");
  1472. goto out_no_surface;
  1473. }
  1474. srf = vmw_res_to_srf(sw_context->res_cache[vmw_res_surface].res);
  1475. vmw_kms_cursor_snoop(srf, sw_context->fp->tfile, &vmw_bo->base,
  1476. header);
  1477. out_no_surface:
  1478. vmw_dmabuf_unreference(&vmw_bo);
  1479. return ret;
  1480. }
  1481. static int vmw_cmd_draw(struct vmw_private *dev_priv,
  1482. struct vmw_sw_context *sw_context,
  1483. SVGA3dCmdHeader *header)
  1484. {
  1485. struct vmw_draw_cmd {
  1486. SVGA3dCmdHeader header;
  1487. SVGA3dCmdDrawPrimitives body;
  1488. } *cmd;
  1489. SVGA3dVertexDecl *decl = (SVGA3dVertexDecl *)(
  1490. (unsigned long)header + sizeof(*cmd));
  1491. SVGA3dPrimitiveRange *range;
  1492. uint32_t i;
  1493. uint32_t maxnum;
  1494. int ret;
  1495. ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
  1496. if (unlikely(ret != 0))
  1497. return ret;
  1498. cmd = container_of(header, struct vmw_draw_cmd, header);
  1499. maxnum = (header->size - sizeof(cmd->body)) / sizeof(*decl);
  1500. if (unlikely(cmd->body.numVertexDecls > maxnum)) {
  1501. DRM_ERROR("Illegal number of vertex declarations.\n");
  1502. return -EINVAL;
  1503. }
  1504. for (i = 0; i < cmd->body.numVertexDecls; ++i, ++decl) {
  1505. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  1506. user_surface_converter,
  1507. &decl->array.surfaceId, NULL);
  1508. if (unlikely(ret != 0))
  1509. return ret;
  1510. }
  1511. maxnum = (header->size - sizeof(cmd->body) -
  1512. cmd->body.numVertexDecls * sizeof(*decl)) / sizeof(*range);
  1513. if (unlikely(cmd->body.numRanges > maxnum)) {
  1514. DRM_ERROR("Illegal number of index ranges.\n");
  1515. return -EINVAL;
  1516. }
  1517. range = (SVGA3dPrimitiveRange *) decl;
  1518. for (i = 0; i < cmd->body.numRanges; ++i, ++range) {
  1519. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  1520. user_surface_converter,
  1521. &range->indexArray.surfaceId, NULL);
  1522. if (unlikely(ret != 0))
  1523. return ret;
  1524. }
  1525. return 0;
  1526. }
  1527. static int vmw_cmd_tex_state(struct vmw_private *dev_priv,
  1528. struct vmw_sw_context *sw_context,
  1529. SVGA3dCmdHeader *header)
  1530. {
  1531. struct vmw_tex_state_cmd {
  1532. SVGA3dCmdHeader header;
  1533. SVGA3dCmdSetTextureState state;
  1534. } *cmd;
  1535. SVGA3dTextureState *last_state = (SVGA3dTextureState *)
  1536. ((unsigned long) header + header->size + sizeof(header));
  1537. SVGA3dTextureState *cur_state = (SVGA3dTextureState *)
  1538. ((unsigned long) header + sizeof(struct vmw_tex_state_cmd));
  1539. struct vmw_resource_val_node *ctx_node;
  1540. struct vmw_resource_val_node *res_node;
  1541. int ret;
  1542. cmd = container_of(header, struct vmw_tex_state_cmd,
  1543. header);
  1544. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
  1545. user_context_converter, &cmd->state.cid,
  1546. &ctx_node);
  1547. if (unlikely(ret != 0))
  1548. return ret;
  1549. for (; cur_state < last_state; ++cur_state) {
  1550. if (likely(cur_state->name != SVGA3D_TS_BIND_TEXTURE))
  1551. continue;
  1552. if (cur_state->stage >= SVGA3D_NUM_TEXTURE_UNITS) {
  1553. DRM_ERROR("Illegal texture/sampler unit %u.\n",
  1554. (unsigned) cur_state->stage);
  1555. return -EINVAL;
  1556. }
  1557. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  1558. user_surface_converter,
  1559. &cur_state->value, &res_node);
  1560. if (unlikely(ret != 0))
  1561. return ret;
  1562. if (dev_priv->has_mob) {
  1563. struct vmw_ctx_bindinfo_tex binding;
  1564. binding.bi.ctx = ctx_node->res;
  1565. binding.bi.res = res_node ? res_node->res : NULL;
  1566. binding.bi.bt = vmw_ctx_binding_tex;
  1567. binding.texture_stage = cur_state->stage;
  1568. vmw_binding_add(ctx_node->staged_bindings, &binding.bi,
  1569. 0, binding.texture_stage);
  1570. }
  1571. }
  1572. return 0;
  1573. }
  1574. static int vmw_cmd_check_define_gmrfb(struct vmw_private *dev_priv,
  1575. struct vmw_sw_context *sw_context,
  1576. void *buf)
  1577. {
  1578. struct vmw_dma_buffer *vmw_bo;
  1579. int ret;
  1580. struct {
  1581. uint32_t header;
  1582. SVGAFifoCmdDefineGMRFB body;
  1583. } *cmd = buf;
  1584. ret = vmw_translate_guest_ptr(dev_priv, sw_context,
  1585. &cmd->body.ptr,
  1586. &vmw_bo);
  1587. if (unlikely(ret != 0))
  1588. return ret;
  1589. vmw_dmabuf_unreference(&vmw_bo);
  1590. return ret;
  1591. }
  1592. /**
  1593. * vmw_cmd_res_switch_backup - Utility function to handle backup buffer
  1594. * switching
  1595. *
  1596. * @dev_priv: Pointer to a device private struct.
  1597. * @sw_context: The software context being used for this batch.
  1598. * @val_node: The validation node representing the resource.
  1599. * @buf_id: Pointer to the user-space backup buffer handle in the command
  1600. * stream.
  1601. * @backup_offset: Offset of backup into MOB.
  1602. *
  1603. * This function prepares for registering a switch of backup buffers
  1604. * in the resource metadata just prior to unreserving. It's basically a wrapper
  1605. * around vmw_cmd_res_switch_backup with a different interface.
  1606. */
  1607. static int vmw_cmd_res_switch_backup(struct vmw_private *dev_priv,
  1608. struct vmw_sw_context *sw_context,
  1609. struct vmw_resource_val_node *val_node,
  1610. uint32_t *buf_id,
  1611. unsigned long backup_offset)
  1612. {
  1613. struct vmw_dma_buffer *dma_buf;
  1614. int ret;
  1615. ret = vmw_translate_mob_ptr(dev_priv, sw_context, buf_id, &dma_buf);
  1616. if (ret)
  1617. return ret;
  1618. val_node->switching_backup = true;
  1619. if (val_node->first_usage)
  1620. val_node->no_buffer_needed = true;
  1621. vmw_dmabuf_unreference(&val_node->new_backup);
  1622. val_node->new_backup = dma_buf;
  1623. val_node->new_backup_offset = backup_offset;
  1624. return 0;
  1625. }
  1626. /**
  1627. * vmw_cmd_switch_backup - Utility function to handle backup buffer switching
  1628. *
  1629. * @dev_priv: Pointer to a device private struct.
  1630. * @sw_context: The software context being used for this batch.
  1631. * @res_type: The resource type.
  1632. * @converter: Information about user-space binding for this resource type.
  1633. * @res_id: Pointer to the user-space resource handle in the command stream.
  1634. * @buf_id: Pointer to the user-space backup buffer handle in the command
  1635. * stream.
  1636. * @backup_offset: Offset of backup into MOB.
  1637. *
  1638. * This function prepares for registering a switch of backup buffers
  1639. * in the resource metadata just prior to unreserving. It's basically a wrapper
  1640. * around vmw_cmd_res_switch_backup with a different interface.
  1641. */
  1642. static int vmw_cmd_switch_backup(struct vmw_private *dev_priv,
  1643. struct vmw_sw_context *sw_context,
  1644. enum vmw_res_type res_type,
  1645. const struct vmw_user_resource_conv
  1646. *converter,
  1647. uint32_t *res_id,
  1648. uint32_t *buf_id,
  1649. unsigned long backup_offset)
  1650. {
  1651. struct vmw_resource_val_node *val_node;
  1652. int ret;
  1653. ret = vmw_cmd_res_check(dev_priv, sw_context, res_type,
  1654. converter, res_id, &val_node);
  1655. if (ret)
  1656. return ret;
  1657. return vmw_cmd_res_switch_backup(dev_priv, sw_context, val_node,
  1658. buf_id, backup_offset);
  1659. }
  1660. /**
  1661. * vmw_cmd_bind_gb_surface - Validate an SVGA_3D_CMD_BIND_GB_SURFACE
  1662. * command
  1663. *
  1664. * @dev_priv: Pointer to a device private struct.
  1665. * @sw_context: The software context being used for this batch.
  1666. * @header: Pointer to the command header in the command stream.
  1667. */
  1668. static int vmw_cmd_bind_gb_surface(struct vmw_private *dev_priv,
  1669. struct vmw_sw_context *sw_context,
  1670. SVGA3dCmdHeader *header)
  1671. {
  1672. struct vmw_bind_gb_surface_cmd {
  1673. SVGA3dCmdHeader header;
  1674. SVGA3dCmdBindGBSurface body;
  1675. } *cmd;
  1676. cmd = container_of(header, struct vmw_bind_gb_surface_cmd, header);
  1677. return vmw_cmd_switch_backup(dev_priv, sw_context, vmw_res_surface,
  1678. user_surface_converter,
  1679. &cmd->body.sid, &cmd->body.mobid,
  1680. 0);
  1681. }
  1682. /**
  1683. * vmw_cmd_update_gb_image - Validate an SVGA_3D_CMD_UPDATE_GB_IMAGE
  1684. * command
  1685. *
  1686. * @dev_priv: Pointer to a device private struct.
  1687. * @sw_context: The software context being used for this batch.
  1688. * @header: Pointer to the command header in the command stream.
  1689. */
  1690. static int vmw_cmd_update_gb_image(struct vmw_private *dev_priv,
  1691. struct vmw_sw_context *sw_context,
  1692. SVGA3dCmdHeader *header)
  1693. {
  1694. struct vmw_gb_surface_cmd {
  1695. SVGA3dCmdHeader header;
  1696. SVGA3dCmdUpdateGBImage body;
  1697. } *cmd;
  1698. cmd = container_of(header, struct vmw_gb_surface_cmd, header);
  1699. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  1700. user_surface_converter,
  1701. &cmd->body.image.sid, NULL);
  1702. }
  1703. /**
  1704. * vmw_cmd_update_gb_surface - Validate an SVGA_3D_CMD_UPDATE_GB_SURFACE
  1705. * command
  1706. *
  1707. * @dev_priv: Pointer to a device private struct.
  1708. * @sw_context: The software context being used for this batch.
  1709. * @header: Pointer to the command header in the command stream.
  1710. */
  1711. static int vmw_cmd_update_gb_surface(struct vmw_private *dev_priv,
  1712. struct vmw_sw_context *sw_context,
  1713. SVGA3dCmdHeader *header)
  1714. {
  1715. struct vmw_gb_surface_cmd {
  1716. SVGA3dCmdHeader header;
  1717. SVGA3dCmdUpdateGBSurface body;
  1718. } *cmd;
  1719. cmd = container_of(header, struct vmw_gb_surface_cmd, header);
  1720. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  1721. user_surface_converter,
  1722. &cmd->body.sid, NULL);
  1723. }
  1724. /**
  1725. * vmw_cmd_readback_gb_image - Validate an SVGA_3D_CMD_READBACK_GB_IMAGE
  1726. * command
  1727. *
  1728. * @dev_priv: Pointer to a device private struct.
  1729. * @sw_context: The software context being used for this batch.
  1730. * @header: Pointer to the command header in the command stream.
  1731. */
  1732. static int vmw_cmd_readback_gb_image(struct vmw_private *dev_priv,
  1733. struct vmw_sw_context *sw_context,
  1734. SVGA3dCmdHeader *header)
  1735. {
  1736. struct vmw_gb_surface_cmd {
  1737. SVGA3dCmdHeader header;
  1738. SVGA3dCmdReadbackGBImage body;
  1739. } *cmd;
  1740. cmd = container_of(header, struct vmw_gb_surface_cmd, header);
  1741. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  1742. user_surface_converter,
  1743. &cmd->body.image.sid, NULL);
  1744. }
  1745. /**
  1746. * vmw_cmd_readback_gb_surface - Validate an SVGA_3D_CMD_READBACK_GB_SURFACE
  1747. * command
  1748. *
  1749. * @dev_priv: Pointer to a device private struct.
  1750. * @sw_context: The software context being used for this batch.
  1751. * @header: Pointer to the command header in the command stream.
  1752. */
  1753. static int vmw_cmd_readback_gb_surface(struct vmw_private *dev_priv,
  1754. struct vmw_sw_context *sw_context,
  1755. SVGA3dCmdHeader *header)
  1756. {
  1757. struct vmw_gb_surface_cmd {
  1758. SVGA3dCmdHeader header;
  1759. SVGA3dCmdReadbackGBSurface body;
  1760. } *cmd;
  1761. cmd = container_of(header, struct vmw_gb_surface_cmd, header);
  1762. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  1763. user_surface_converter,
  1764. &cmd->body.sid, NULL);
  1765. }
  1766. /**
  1767. * vmw_cmd_invalidate_gb_image - Validate an SVGA_3D_CMD_INVALIDATE_GB_IMAGE
  1768. * command
  1769. *
  1770. * @dev_priv: Pointer to a device private struct.
  1771. * @sw_context: The software context being used for this batch.
  1772. * @header: Pointer to the command header in the command stream.
  1773. */
  1774. static int vmw_cmd_invalidate_gb_image(struct vmw_private *dev_priv,
  1775. struct vmw_sw_context *sw_context,
  1776. SVGA3dCmdHeader *header)
  1777. {
  1778. struct vmw_gb_surface_cmd {
  1779. SVGA3dCmdHeader header;
  1780. SVGA3dCmdInvalidateGBImage body;
  1781. } *cmd;
  1782. cmd = container_of(header, struct vmw_gb_surface_cmd, header);
  1783. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  1784. user_surface_converter,
  1785. &cmd->body.image.sid, NULL);
  1786. }
  1787. /**
  1788. * vmw_cmd_invalidate_gb_surface - Validate an
  1789. * SVGA_3D_CMD_INVALIDATE_GB_SURFACE command
  1790. *
  1791. * @dev_priv: Pointer to a device private struct.
  1792. * @sw_context: The software context being used for this batch.
  1793. * @header: Pointer to the command header in the command stream.
  1794. */
  1795. static int vmw_cmd_invalidate_gb_surface(struct vmw_private *dev_priv,
  1796. struct vmw_sw_context *sw_context,
  1797. SVGA3dCmdHeader *header)
  1798. {
  1799. struct vmw_gb_surface_cmd {
  1800. SVGA3dCmdHeader header;
  1801. SVGA3dCmdInvalidateGBSurface body;
  1802. } *cmd;
  1803. cmd = container_of(header, struct vmw_gb_surface_cmd, header);
  1804. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  1805. user_surface_converter,
  1806. &cmd->body.sid, NULL);
  1807. }
  1808. /**
  1809. * vmw_cmd_shader_define - Validate an SVGA_3D_CMD_SHADER_DEFINE
  1810. * command
  1811. *
  1812. * @dev_priv: Pointer to a device private struct.
  1813. * @sw_context: The software context being used for this batch.
  1814. * @header: Pointer to the command header in the command stream.
  1815. */
  1816. static int vmw_cmd_shader_define(struct vmw_private *dev_priv,
  1817. struct vmw_sw_context *sw_context,
  1818. SVGA3dCmdHeader *header)
  1819. {
  1820. struct vmw_shader_define_cmd {
  1821. SVGA3dCmdHeader header;
  1822. SVGA3dCmdDefineShader body;
  1823. } *cmd;
  1824. int ret;
  1825. size_t size;
  1826. struct vmw_resource_val_node *val;
  1827. cmd = container_of(header, struct vmw_shader_define_cmd,
  1828. header);
  1829. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
  1830. user_context_converter, &cmd->body.cid,
  1831. &val);
  1832. if (unlikely(ret != 0))
  1833. return ret;
  1834. if (unlikely(!dev_priv->has_mob))
  1835. return 0;
  1836. size = cmd->header.size - sizeof(cmd->body);
  1837. ret = vmw_compat_shader_add(dev_priv,
  1838. vmw_context_res_man(val->res),
  1839. cmd->body.shid, cmd + 1,
  1840. cmd->body.type, size,
  1841. &sw_context->staged_cmd_res);
  1842. if (unlikely(ret != 0))
  1843. return ret;
  1844. return vmw_resource_relocation_add(&sw_context->res_relocations,
  1845. NULL, &cmd->header.id -
  1846. sw_context->buf_start);
  1847. return 0;
  1848. }
  1849. /**
  1850. * vmw_cmd_shader_destroy - Validate an SVGA_3D_CMD_SHADER_DESTROY
  1851. * command
  1852. *
  1853. * @dev_priv: Pointer to a device private struct.
  1854. * @sw_context: The software context being used for this batch.
  1855. * @header: Pointer to the command header in the command stream.
  1856. */
  1857. static int vmw_cmd_shader_destroy(struct vmw_private *dev_priv,
  1858. struct vmw_sw_context *sw_context,
  1859. SVGA3dCmdHeader *header)
  1860. {
  1861. struct vmw_shader_destroy_cmd {
  1862. SVGA3dCmdHeader header;
  1863. SVGA3dCmdDestroyShader body;
  1864. } *cmd;
  1865. int ret;
  1866. struct vmw_resource_val_node *val;
  1867. cmd = container_of(header, struct vmw_shader_destroy_cmd,
  1868. header);
  1869. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
  1870. user_context_converter, &cmd->body.cid,
  1871. &val);
  1872. if (unlikely(ret != 0))
  1873. return ret;
  1874. if (unlikely(!dev_priv->has_mob))
  1875. return 0;
  1876. ret = vmw_shader_remove(vmw_context_res_man(val->res),
  1877. cmd->body.shid,
  1878. cmd->body.type,
  1879. &sw_context->staged_cmd_res);
  1880. if (unlikely(ret != 0))
  1881. return ret;
  1882. return vmw_resource_relocation_add(&sw_context->res_relocations,
  1883. NULL, &cmd->header.id -
  1884. sw_context->buf_start);
  1885. return 0;
  1886. }
  1887. /**
  1888. * vmw_cmd_set_shader - Validate an SVGA_3D_CMD_SET_SHADER
  1889. * command
  1890. *
  1891. * @dev_priv: Pointer to a device private struct.
  1892. * @sw_context: The software context being used for this batch.
  1893. * @header: Pointer to the command header in the command stream.
  1894. */
  1895. static int vmw_cmd_set_shader(struct vmw_private *dev_priv,
  1896. struct vmw_sw_context *sw_context,
  1897. SVGA3dCmdHeader *header)
  1898. {
  1899. struct vmw_set_shader_cmd {
  1900. SVGA3dCmdHeader header;
  1901. SVGA3dCmdSetShader body;
  1902. } *cmd;
  1903. struct vmw_resource_val_node *ctx_node, *res_node = NULL;
  1904. struct vmw_ctx_bindinfo_shader binding;
  1905. struct vmw_resource *res = NULL;
  1906. int ret;
  1907. cmd = container_of(header, struct vmw_set_shader_cmd,
  1908. header);
  1909. if (cmd->body.type >= SVGA3D_SHADERTYPE_PREDX_MAX) {
  1910. DRM_ERROR("Illegal shader type %u.\n",
  1911. (unsigned) cmd->body.type);
  1912. return -EINVAL;
  1913. }
  1914. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
  1915. user_context_converter, &cmd->body.cid,
  1916. &ctx_node);
  1917. if (unlikely(ret != 0))
  1918. return ret;
  1919. if (!dev_priv->has_mob)
  1920. return 0;
  1921. if (cmd->body.shid != SVGA3D_INVALID_ID) {
  1922. res = vmw_shader_lookup(vmw_context_res_man(ctx_node->res),
  1923. cmd->body.shid,
  1924. cmd->body.type);
  1925. if (!IS_ERR(res)) {
  1926. ret = vmw_cmd_res_reloc_add(dev_priv, sw_context,
  1927. &cmd->body.shid, res,
  1928. &res_node);
  1929. vmw_resource_unreference(&res);
  1930. if (unlikely(ret != 0))
  1931. return ret;
  1932. }
  1933. }
  1934. if (!res_node) {
  1935. ret = vmw_cmd_res_check(dev_priv, sw_context,
  1936. vmw_res_shader,
  1937. user_shader_converter,
  1938. &cmd->body.shid, &res_node);
  1939. if (unlikely(ret != 0))
  1940. return ret;
  1941. }
  1942. binding.bi.ctx = ctx_node->res;
  1943. binding.bi.res = res_node ? res_node->res : NULL;
  1944. binding.bi.bt = vmw_ctx_binding_shader;
  1945. binding.shader_slot = cmd->body.type - SVGA3D_SHADERTYPE_MIN;
  1946. vmw_binding_add(ctx_node->staged_bindings, &binding.bi,
  1947. binding.shader_slot, 0);
  1948. return 0;
  1949. }
  1950. /**
  1951. * vmw_cmd_set_shader_const - Validate an SVGA_3D_CMD_SET_SHADER_CONST
  1952. * command
  1953. *
  1954. * @dev_priv: Pointer to a device private struct.
  1955. * @sw_context: The software context being used for this batch.
  1956. * @header: Pointer to the command header in the command stream.
  1957. */
  1958. static int vmw_cmd_set_shader_const(struct vmw_private *dev_priv,
  1959. struct vmw_sw_context *sw_context,
  1960. SVGA3dCmdHeader *header)
  1961. {
  1962. struct vmw_set_shader_const_cmd {
  1963. SVGA3dCmdHeader header;
  1964. SVGA3dCmdSetShaderConst body;
  1965. } *cmd;
  1966. int ret;
  1967. cmd = container_of(header, struct vmw_set_shader_const_cmd,
  1968. header);
  1969. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
  1970. user_context_converter, &cmd->body.cid,
  1971. NULL);
  1972. if (unlikely(ret != 0))
  1973. return ret;
  1974. if (dev_priv->has_mob)
  1975. header->id = SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE;
  1976. return 0;
  1977. }
  1978. /**
  1979. * vmw_cmd_bind_gb_shader - Validate an SVGA_3D_CMD_BIND_GB_SHADER
  1980. * command
  1981. *
  1982. * @dev_priv: Pointer to a device private struct.
  1983. * @sw_context: The software context being used for this batch.
  1984. * @header: Pointer to the command header in the command stream.
  1985. */
  1986. static int vmw_cmd_bind_gb_shader(struct vmw_private *dev_priv,
  1987. struct vmw_sw_context *sw_context,
  1988. SVGA3dCmdHeader *header)
  1989. {
  1990. struct vmw_bind_gb_shader_cmd {
  1991. SVGA3dCmdHeader header;
  1992. SVGA3dCmdBindGBShader body;
  1993. } *cmd;
  1994. cmd = container_of(header, struct vmw_bind_gb_shader_cmd,
  1995. header);
  1996. return vmw_cmd_switch_backup(dev_priv, sw_context, vmw_res_shader,
  1997. user_shader_converter,
  1998. &cmd->body.shid, &cmd->body.mobid,
  1999. cmd->body.offsetInBytes);
  2000. }
  2001. /**
  2002. * vmw_cmd_dx_set_single_constant_buffer - Validate an
  2003. * SVGA_3D_CMD_DX_SET_SINGLE_CONSTANT_BUFFER command.
  2004. *
  2005. * @dev_priv: Pointer to a device private struct.
  2006. * @sw_context: The software context being used for this batch.
  2007. * @header: Pointer to the command header in the command stream.
  2008. */
  2009. static int
  2010. vmw_cmd_dx_set_single_constant_buffer(struct vmw_private *dev_priv,
  2011. struct vmw_sw_context *sw_context,
  2012. SVGA3dCmdHeader *header)
  2013. {
  2014. struct {
  2015. SVGA3dCmdHeader header;
  2016. SVGA3dCmdDXSetSingleConstantBuffer body;
  2017. } *cmd;
  2018. struct vmw_resource_val_node *res_node = NULL;
  2019. struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
  2020. struct vmw_ctx_bindinfo_cb binding;
  2021. int ret;
  2022. if (unlikely(ctx_node == NULL)) {
  2023. DRM_ERROR("DX Context not set.\n");
  2024. return -EINVAL;
  2025. }
  2026. cmd = container_of(header, typeof(*cmd), header);
  2027. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  2028. user_surface_converter,
  2029. &cmd->body.sid, &res_node);
  2030. if (unlikely(ret != 0))
  2031. return ret;
  2032. binding.bi.ctx = ctx_node->res;
  2033. binding.bi.res = res_node ? res_node->res : NULL;
  2034. binding.bi.bt = vmw_ctx_binding_cb;
  2035. binding.shader_slot = cmd->body.type - SVGA3D_SHADERTYPE_MIN;
  2036. binding.offset = cmd->body.offsetInBytes;
  2037. binding.size = cmd->body.sizeInBytes;
  2038. binding.slot = cmd->body.slot;
  2039. if (binding.shader_slot >= SVGA3D_NUM_SHADERTYPE_DX10 ||
  2040. binding.slot >= SVGA3D_DX_MAX_CONSTBUFFERS) {
  2041. DRM_ERROR("Illegal const buffer shader %u slot %u.\n",
  2042. (unsigned) cmd->body.type,
  2043. (unsigned) binding.slot);
  2044. return -EINVAL;
  2045. }
  2046. vmw_binding_add(ctx_node->staged_bindings, &binding.bi,
  2047. binding.shader_slot, binding.slot);
  2048. return 0;
  2049. }
  2050. /**
  2051. * vmw_cmd_dx_set_shader_res - Validate an
  2052. * SVGA_3D_CMD_DX_SET_SHADER_RESOURCES command
  2053. *
  2054. * @dev_priv: Pointer to a device private struct.
  2055. * @sw_context: The software context being used for this batch.
  2056. * @header: Pointer to the command header in the command stream.
  2057. */
  2058. static int vmw_cmd_dx_set_shader_res(struct vmw_private *dev_priv,
  2059. struct vmw_sw_context *sw_context,
  2060. SVGA3dCmdHeader *header)
  2061. {
  2062. struct {
  2063. SVGA3dCmdHeader header;
  2064. SVGA3dCmdDXSetShaderResources body;
  2065. } *cmd = container_of(header, typeof(*cmd), header);
  2066. u32 num_sr_view = (cmd->header.size - sizeof(cmd->body)) /
  2067. sizeof(SVGA3dShaderResourceViewId);
  2068. if ((u64) cmd->body.startView + (u64) num_sr_view >
  2069. (u64) SVGA3D_DX_MAX_SRVIEWS ||
  2070. cmd->body.type >= SVGA3D_SHADERTYPE_DX10_MAX) {
  2071. DRM_ERROR("Invalid shader binding.\n");
  2072. return -EINVAL;
  2073. }
  2074. return vmw_view_bindings_add(sw_context, vmw_view_sr,
  2075. vmw_ctx_binding_sr,
  2076. cmd->body.type - SVGA3D_SHADERTYPE_MIN,
  2077. (void *) &cmd[1], num_sr_view,
  2078. cmd->body.startView);
  2079. }
  2080. /**
  2081. * vmw_cmd_dx_set_shader - Validate an SVGA_3D_CMD_DX_SET_SHADER
  2082. * command
  2083. *
  2084. * @dev_priv: Pointer to a device private struct.
  2085. * @sw_context: The software context being used for this batch.
  2086. * @header: Pointer to the command header in the command stream.
  2087. */
  2088. static int vmw_cmd_dx_set_shader(struct vmw_private *dev_priv,
  2089. struct vmw_sw_context *sw_context,
  2090. SVGA3dCmdHeader *header)
  2091. {
  2092. struct {
  2093. SVGA3dCmdHeader header;
  2094. SVGA3dCmdDXSetShader body;
  2095. } *cmd;
  2096. struct vmw_resource *res = NULL;
  2097. struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
  2098. struct vmw_ctx_bindinfo_shader binding;
  2099. int ret = 0;
  2100. if (unlikely(ctx_node == NULL)) {
  2101. DRM_ERROR("DX Context not set.\n");
  2102. return -EINVAL;
  2103. }
  2104. cmd = container_of(header, typeof(*cmd), header);
  2105. if (cmd->body.type >= SVGA3D_SHADERTYPE_DX10_MAX) {
  2106. DRM_ERROR("Illegal shader type %u.\n",
  2107. (unsigned) cmd->body.type);
  2108. return -EINVAL;
  2109. }
  2110. if (cmd->body.shaderId != SVGA3D_INVALID_ID) {
  2111. res = vmw_shader_lookup(sw_context->man, cmd->body.shaderId, 0);
  2112. if (IS_ERR(res)) {
  2113. DRM_ERROR("Could not find shader for binding.\n");
  2114. return PTR_ERR(res);
  2115. }
  2116. ret = vmw_resource_val_add(sw_context, res, NULL);
  2117. if (ret)
  2118. goto out_unref;
  2119. }
  2120. binding.bi.ctx = ctx_node->res;
  2121. binding.bi.res = res;
  2122. binding.bi.bt = vmw_ctx_binding_dx_shader;
  2123. binding.shader_slot = cmd->body.type - SVGA3D_SHADERTYPE_MIN;
  2124. vmw_binding_add(ctx_node->staged_bindings, &binding.bi,
  2125. binding.shader_slot, 0);
  2126. out_unref:
  2127. if (res)
  2128. vmw_resource_unreference(&res);
  2129. return ret;
  2130. }
  2131. /**
  2132. * vmw_cmd_dx_set_vertex_buffers - Validates an
  2133. * SVGA_3D_CMD_DX_SET_VERTEX_BUFFERS command
  2134. *
  2135. * @dev_priv: Pointer to a device private struct.
  2136. * @sw_context: The software context being used for this batch.
  2137. * @header: Pointer to the command header in the command stream.
  2138. */
  2139. static int vmw_cmd_dx_set_vertex_buffers(struct vmw_private *dev_priv,
  2140. struct vmw_sw_context *sw_context,
  2141. SVGA3dCmdHeader *header)
  2142. {
  2143. struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
  2144. struct vmw_ctx_bindinfo_vb binding;
  2145. struct vmw_resource_val_node *res_node;
  2146. struct {
  2147. SVGA3dCmdHeader header;
  2148. SVGA3dCmdDXSetVertexBuffers body;
  2149. SVGA3dVertexBuffer buf[];
  2150. } *cmd;
  2151. int i, ret, num;
  2152. if (unlikely(ctx_node == NULL)) {
  2153. DRM_ERROR("DX Context not set.\n");
  2154. return -EINVAL;
  2155. }
  2156. cmd = container_of(header, typeof(*cmd), header);
  2157. num = (cmd->header.size - sizeof(cmd->body)) /
  2158. sizeof(SVGA3dVertexBuffer);
  2159. if ((u64)num + (u64)cmd->body.startBuffer >
  2160. (u64)SVGA3D_DX_MAX_VERTEXBUFFERS) {
  2161. DRM_ERROR("Invalid number of vertex buffers.\n");
  2162. return -EINVAL;
  2163. }
  2164. for (i = 0; i < num; i++) {
  2165. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  2166. user_surface_converter,
  2167. &cmd->buf[i].sid, &res_node);
  2168. if (unlikely(ret != 0))
  2169. return ret;
  2170. binding.bi.ctx = ctx_node->res;
  2171. binding.bi.bt = vmw_ctx_binding_vb;
  2172. binding.bi.res = ((res_node) ? res_node->res : NULL);
  2173. binding.offset = cmd->buf[i].offset;
  2174. binding.stride = cmd->buf[i].stride;
  2175. binding.slot = i + cmd->body.startBuffer;
  2176. vmw_binding_add(ctx_node->staged_bindings, &binding.bi,
  2177. 0, binding.slot);
  2178. }
  2179. return 0;
  2180. }
  2181. /**
  2182. * vmw_cmd_dx_ia_set_vertex_buffers - Validate an
  2183. * SVGA_3D_CMD_DX_IA_SET_VERTEX_BUFFERS command.
  2184. *
  2185. * @dev_priv: Pointer to a device private struct.
  2186. * @sw_context: The software context being used for this batch.
  2187. * @header: Pointer to the command header in the command stream.
  2188. */
  2189. static int vmw_cmd_dx_set_index_buffer(struct vmw_private *dev_priv,
  2190. struct vmw_sw_context *sw_context,
  2191. SVGA3dCmdHeader *header)
  2192. {
  2193. struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
  2194. struct vmw_ctx_bindinfo_ib binding;
  2195. struct vmw_resource_val_node *res_node;
  2196. struct {
  2197. SVGA3dCmdHeader header;
  2198. SVGA3dCmdDXSetIndexBuffer body;
  2199. } *cmd;
  2200. int ret;
  2201. if (unlikely(ctx_node == NULL)) {
  2202. DRM_ERROR("DX Context not set.\n");
  2203. return -EINVAL;
  2204. }
  2205. cmd = container_of(header, typeof(*cmd), header);
  2206. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  2207. user_surface_converter,
  2208. &cmd->body.sid, &res_node);
  2209. if (unlikely(ret != 0))
  2210. return ret;
  2211. binding.bi.ctx = ctx_node->res;
  2212. binding.bi.res = ((res_node) ? res_node->res : NULL);
  2213. binding.bi.bt = vmw_ctx_binding_ib;
  2214. binding.offset = cmd->body.offset;
  2215. binding.format = cmd->body.format;
  2216. vmw_binding_add(ctx_node->staged_bindings, &binding.bi, 0, 0);
  2217. return 0;
  2218. }
  2219. /**
  2220. * vmw_cmd_dx_set_rendertarget - Validate an
  2221. * SVGA_3D_CMD_DX_SET_RENDERTARGETS command
  2222. *
  2223. * @dev_priv: Pointer to a device private struct.
  2224. * @sw_context: The software context being used for this batch.
  2225. * @header: Pointer to the command header in the command stream.
  2226. */
  2227. static int vmw_cmd_dx_set_rendertargets(struct vmw_private *dev_priv,
  2228. struct vmw_sw_context *sw_context,
  2229. SVGA3dCmdHeader *header)
  2230. {
  2231. struct {
  2232. SVGA3dCmdHeader header;
  2233. SVGA3dCmdDXSetRenderTargets body;
  2234. } *cmd = container_of(header, typeof(*cmd), header);
  2235. int ret;
  2236. u32 num_rt_view = (cmd->header.size - sizeof(cmd->body)) /
  2237. sizeof(SVGA3dRenderTargetViewId);
  2238. if (num_rt_view > SVGA3D_MAX_SIMULTANEOUS_RENDER_TARGETS) {
  2239. DRM_ERROR("Invalid DX Rendertarget binding.\n");
  2240. return -EINVAL;
  2241. }
  2242. ret = vmw_view_bindings_add(sw_context, vmw_view_ds,
  2243. vmw_ctx_binding_ds, 0,
  2244. &cmd->body.depthStencilViewId, 1, 0);
  2245. if (ret)
  2246. return ret;
  2247. return vmw_view_bindings_add(sw_context, vmw_view_rt,
  2248. vmw_ctx_binding_dx_rt, 0,
  2249. (void *)&cmd[1], num_rt_view, 0);
  2250. }
  2251. /**
  2252. * vmw_cmd_dx_clear_rendertarget_view - Validate an
  2253. * SVGA_3D_CMD_DX_CLEAR_RENDERTARGET_VIEW command
  2254. *
  2255. * @dev_priv: Pointer to a device private struct.
  2256. * @sw_context: The software context being used for this batch.
  2257. * @header: Pointer to the command header in the command stream.
  2258. */
  2259. static int vmw_cmd_dx_clear_rendertarget_view(struct vmw_private *dev_priv,
  2260. struct vmw_sw_context *sw_context,
  2261. SVGA3dCmdHeader *header)
  2262. {
  2263. struct {
  2264. SVGA3dCmdHeader header;
  2265. SVGA3dCmdDXClearRenderTargetView body;
  2266. } *cmd = container_of(header, typeof(*cmd), header);
  2267. return vmw_view_id_val_add(sw_context, vmw_view_rt,
  2268. cmd->body.renderTargetViewId);
  2269. }
  2270. /**
  2271. * vmw_cmd_dx_clear_rendertarget_view - Validate an
  2272. * SVGA_3D_CMD_DX_CLEAR_DEPTHSTENCIL_VIEW command
  2273. *
  2274. * @dev_priv: Pointer to a device private struct.
  2275. * @sw_context: The software context being used for this batch.
  2276. * @header: Pointer to the command header in the command stream.
  2277. */
  2278. static int vmw_cmd_dx_clear_depthstencil_view(struct vmw_private *dev_priv,
  2279. struct vmw_sw_context *sw_context,
  2280. SVGA3dCmdHeader *header)
  2281. {
  2282. struct {
  2283. SVGA3dCmdHeader header;
  2284. SVGA3dCmdDXClearDepthStencilView body;
  2285. } *cmd = container_of(header, typeof(*cmd), header);
  2286. return vmw_view_id_val_add(sw_context, vmw_view_ds,
  2287. cmd->body.depthStencilViewId);
  2288. }
  2289. static int vmw_cmd_dx_view_define(struct vmw_private *dev_priv,
  2290. struct vmw_sw_context *sw_context,
  2291. SVGA3dCmdHeader *header)
  2292. {
  2293. struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
  2294. struct vmw_resource_val_node *srf_node;
  2295. struct vmw_resource *res;
  2296. enum vmw_view_type view_type;
  2297. int ret;
  2298. /*
  2299. * This is based on the fact that all affected define commands have
  2300. * the same initial command body layout.
  2301. */
  2302. struct {
  2303. SVGA3dCmdHeader header;
  2304. uint32 defined_id;
  2305. uint32 sid;
  2306. } *cmd;
  2307. if (unlikely(ctx_node == NULL)) {
  2308. DRM_ERROR("DX Context not set.\n");
  2309. return -EINVAL;
  2310. }
  2311. view_type = vmw_view_cmd_to_type(header->id);
  2312. cmd = container_of(header, typeof(*cmd), header);
  2313. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  2314. user_surface_converter,
  2315. &cmd->sid, &srf_node);
  2316. if (unlikely(ret != 0))
  2317. return ret;
  2318. res = vmw_context_cotable(ctx_node->res, vmw_view_cotables[view_type]);
  2319. ret = vmw_cotable_notify(res, cmd->defined_id);
  2320. vmw_resource_unreference(&res);
  2321. if (unlikely(ret != 0))
  2322. return ret;
  2323. return vmw_view_add(sw_context->man,
  2324. ctx_node->res,
  2325. srf_node->res,
  2326. view_type,
  2327. cmd->defined_id,
  2328. header,
  2329. header->size + sizeof(*header),
  2330. &sw_context->staged_cmd_res);
  2331. }
  2332. /**
  2333. * vmw_cmd_dx_set_so_targets - Validate an
  2334. * SVGA_3D_CMD_DX_SET_SOTARGETS command.
  2335. *
  2336. * @dev_priv: Pointer to a device private struct.
  2337. * @sw_context: The software context being used for this batch.
  2338. * @header: Pointer to the command header in the command stream.
  2339. */
  2340. static int vmw_cmd_dx_set_so_targets(struct vmw_private *dev_priv,
  2341. struct vmw_sw_context *sw_context,
  2342. SVGA3dCmdHeader *header)
  2343. {
  2344. struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
  2345. struct vmw_ctx_bindinfo_so binding;
  2346. struct vmw_resource_val_node *res_node;
  2347. struct {
  2348. SVGA3dCmdHeader header;
  2349. SVGA3dCmdDXSetSOTargets body;
  2350. SVGA3dSoTarget targets[];
  2351. } *cmd;
  2352. int i, ret, num;
  2353. if (unlikely(ctx_node == NULL)) {
  2354. DRM_ERROR("DX Context not set.\n");
  2355. return -EINVAL;
  2356. }
  2357. cmd = container_of(header, typeof(*cmd), header);
  2358. num = (cmd->header.size - sizeof(cmd->body)) /
  2359. sizeof(SVGA3dSoTarget);
  2360. if (num > SVGA3D_DX_MAX_SOTARGETS) {
  2361. DRM_ERROR("Invalid DX SO binding.\n");
  2362. return -EINVAL;
  2363. }
  2364. for (i = 0; i < num; i++) {
  2365. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  2366. user_surface_converter,
  2367. &cmd->targets[i].sid, &res_node);
  2368. if (unlikely(ret != 0))
  2369. return ret;
  2370. binding.bi.ctx = ctx_node->res;
  2371. binding.bi.res = ((res_node) ? res_node->res : NULL);
  2372. binding.bi.bt = vmw_ctx_binding_so,
  2373. binding.offset = cmd->targets[i].offset;
  2374. binding.size = cmd->targets[i].sizeInBytes;
  2375. binding.slot = i;
  2376. vmw_binding_add(ctx_node->staged_bindings, &binding.bi,
  2377. 0, binding.slot);
  2378. }
  2379. return 0;
  2380. }
  2381. static int vmw_cmd_dx_so_define(struct vmw_private *dev_priv,
  2382. struct vmw_sw_context *sw_context,
  2383. SVGA3dCmdHeader *header)
  2384. {
  2385. struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
  2386. struct vmw_resource *res;
  2387. /*
  2388. * This is based on the fact that all affected define commands have
  2389. * the same initial command body layout.
  2390. */
  2391. struct {
  2392. SVGA3dCmdHeader header;
  2393. uint32 defined_id;
  2394. } *cmd;
  2395. enum vmw_so_type so_type;
  2396. int ret;
  2397. if (unlikely(ctx_node == NULL)) {
  2398. DRM_ERROR("DX Context not set.\n");
  2399. return -EINVAL;
  2400. }
  2401. so_type = vmw_so_cmd_to_type(header->id);
  2402. res = vmw_context_cotable(ctx_node->res, vmw_so_cotables[so_type]);
  2403. cmd = container_of(header, typeof(*cmd), header);
  2404. ret = vmw_cotable_notify(res, cmd->defined_id);
  2405. vmw_resource_unreference(&res);
  2406. return ret;
  2407. }
  2408. /**
  2409. * vmw_cmd_dx_check_subresource - Validate an
  2410. * SVGA_3D_CMD_DX_[X]_SUBRESOURCE command
  2411. *
  2412. * @dev_priv: Pointer to a device private struct.
  2413. * @sw_context: The software context being used for this batch.
  2414. * @header: Pointer to the command header in the command stream.
  2415. */
  2416. static int vmw_cmd_dx_check_subresource(struct vmw_private *dev_priv,
  2417. struct vmw_sw_context *sw_context,
  2418. SVGA3dCmdHeader *header)
  2419. {
  2420. struct {
  2421. SVGA3dCmdHeader header;
  2422. union {
  2423. SVGA3dCmdDXReadbackSubResource r_body;
  2424. SVGA3dCmdDXInvalidateSubResource i_body;
  2425. SVGA3dCmdDXUpdateSubResource u_body;
  2426. SVGA3dSurfaceId sid;
  2427. };
  2428. } *cmd;
  2429. BUILD_BUG_ON(offsetof(typeof(*cmd), r_body.sid) !=
  2430. offsetof(typeof(*cmd), sid));
  2431. BUILD_BUG_ON(offsetof(typeof(*cmd), i_body.sid) !=
  2432. offsetof(typeof(*cmd), sid));
  2433. BUILD_BUG_ON(offsetof(typeof(*cmd), u_body.sid) !=
  2434. offsetof(typeof(*cmd), sid));
  2435. cmd = container_of(header, typeof(*cmd), header);
  2436. return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
  2437. user_surface_converter,
  2438. &cmd->sid, NULL);
  2439. }
  2440. static int vmw_cmd_dx_cid_check(struct vmw_private *dev_priv,
  2441. struct vmw_sw_context *sw_context,
  2442. SVGA3dCmdHeader *header)
  2443. {
  2444. struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
  2445. if (unlikely(ctx_node == NULL)) {
  2446. DRM_ERROR("DX Context not set.\n");
  2447. return -EINVAL;
  2448. }
  2449. return 0;
  2450. }
  2451. /**
  2452. * vmw_cmd_dx_view_remove - validate a view remove command and
  2453. * schedule the view resource for removal.
  2454. *
  2455. * @dev_priv: Pointer to a device private struct.
  2456. * @sw_context: The software context being used for this batch.
  2457. * @header: Pointer to the command header in the command stream.
  2458. *
  2459. * Check that the view exists, and if it was not created using this
  2460. * command batch, make sure it's validated (present in the device) so that
  2461. * the remove command will not confuse the device.
  2462. */
  2463. static int vmw_cmd_dx_view_remove(struct vmw_private *dev_priv,
  2464. struct vmw_sw_context *sw_context,
  2465. SVGA3dCmdHeader *header)
  2466. {
  2467. struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
  2468. struct {
  2469. SVGA3dCmdHeader header;
  2470. union vmw_view_destroy body;
  2471. } *cmd = container_of(header, typeof(*cmd), header);
  2472. enum vmw_view_type view_type = vmw_view_cmd_to_type(header->id);
  2473. struct vmw_resource *view;
  2474. int ret;
  2475. if (!ctx_node) {
  2476. DRM_ERROR("DX Context not set.\n");
  2477. return -EINVAL;
  2478. }
  2479. ret = vmw_view_remove(sw_context->man,
  2480. cmd->body.view_id, view_type,
  2481. &sw_context->staged_cmd_res,
  2482. &view);
  2483. if (ret || !view)
  2484. return ret;
  2485. /*
  2486. * Add view to the validate list iff it was not created using this
  2487. * command batch.
  2488. */
  2489. return vmw_view_res_val_add(sw_context, view);
  2490. }
  2491. /**
  2492. * vmw_cmd_dx_define_shader - Validate an SVGA_3D_CMD_DX_DEFINE_SHADER
  2493. * command
  2494. *
  2495. * @dev_priv: Pointer to a device private struct.
  2496. * @sw_context: The software context being used for this batch.
  2497. * @header: Pointer to the command header in the command stream.
  2498. */
  2499. static int vmw_cmd_dx_define_shader(struct vmw_private *dev_priv,
  2500. struct vmw_sw_context *sw_context,
  2501. SVGA3dCmdHeader *header)
  2502. {
  2503. struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
  2504. struct vmw_resource *res;
  2505. struct {
  2506. SVGA3dCmdHeader header;
  2507. SVGA3dCmdDXDefineShader body;
  2508. } *cmd = container_of(header, typeof(*cmd), header);
  2509. int ret;
  2510. if (!ctx_node) {
  2511. DRM_ERROR("DX Context not set.\n");
  2512. return -EINVAL;
  2513. }
  2514. res = vmw_context_cotable(ctx_node->res, SVGA_COTABLE_DXSHADER);
  2515. ret = vmw_cotable_notify(res, cmd->body.shaderId);
  2516. vmw_resource_unreference(&res);
  2517. if (ret)
  2518. return ret;
  2519. return vmw_dx_shader_add(sw_context->man, ctx_node->res,
  2520. cmd->body.shaderId, cmd->body.type,
  2521. &sw_context->staged_cmd_res);
  2522. }
  2523. /**
  2524. * vmw_cmd_dx_destroy_shader - Validate an SVGA_3D_CMD_DX_DESTROY_SHADER
  2525. * command
  2526. *
  2527. * @dev_priv: Pointer to a device private struct.
  2528. * @sw_context: The software context being used for this batch.
  2529. * @header: Pointer to the command header in the command stream.
  2530. */
  2531. static int vmw_cmd_dx_destroy_shader(struct vmw_private *dev_priv,
  2532. struct vmw_sw_context *sw_context,
  2533. SVGA3dCmdHeader *header)
  2534. {
  2535. struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
  2536. struct {
  2537. SVGA3dCmdHeader header;
  2538. SVGA3dCmdDXDestroyShader body;
  2539. } *cmd = container_of(header, typeof(*cmd), header);
  2540. int ret;
  2541. if (!ctx_node) {
  2542. DRM_ERROR("DX Context not set.\n");
  2543. return -EINVAL;
  2544. }
  2545. ret = vmw_shader_remove(sw_context->man, cmd->body.shaderId, 0,
  2546. &sw_context->staged_cmd_res);
  2547. if (ret)
  2548. DRM_ERROR("Could not find shader to remove.\n");
  2549. return ret;
  2550. }
  2551. /**
  2552. * vmw_cmd_dx_bind_shader - Validate an SVGA_3D_CMD_DX_BIND_SHADER
  2553. * command
  2554. *
  2555. * @dev_priv: Pointer to a device private struct.
  2556. * @sw_context: The software context being used for this batch.
  2557. * @header: Pointer to the command header in the command stream.
  2558. */
  2559. static int vmw_cmd_dx_bind_shader(struct vmw_private *dev_priv,
  2560. struct vmw_sw_context *sw_context,
  2561. SVGA3dCmdHeader *header)
  2562. {
  2563. struct vmw_resource_val_node *ctx_node;
  2564. struct vmw_resource_val_node *res_node;
  2565. struct vmw_resource *res;
  2566. struct {
  2567. SVGA3dCmdHeader header;
  2568. SVGA3dCmdDXBindShader body;
  2569. } *cmd = container_of(header, typeof(*cmd), header);
  2570. int ret;
  2571. if (cmd->body.cid != SVGA3D_INVALID_ID) {
  2572. ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
  2573. user_context_converter,
  2574. &cmd->body.cid, &ctx_node);
  2575. if (ret)
  2576. return ret;
  2577. } else {
  2578. ctx_node = sw_context->dx_ctx_node;
  2579. if (!ctx_node) {
  2580. DRM_ERROR("DX Context not set.\n");
  2581. return -EINVAL;
  2582. }
  2583. }
  2584. res = vmw_shader_lookup(vmw_context_res_man(ctx_node->res),
  2585. cmd->body.shid, 0);
  2586. if (IS_ERR(res)) {
  2587. DRM_ERROR("Could not find shader to bind.\n");
  2588. return PTR_ERR(res);
  2589. }
  2590. ret = vmw_resource_val_add(sw_context, res, &res_node);
  2591. if (ret) {
  2592. DRM_ERROR("Error creating resource validation node.\n");
  2593. goto out_unref;
  2594. }
  2595. ret = vmw_cmd_res_switch_backup(dev_priv, sw_context, res_node,
  2596. &cmd->body.mobid,
  2597. cmd->body.offsetInBytes);
  2598. out_unref:
  2599. vmw_resource_unreference(&res);
  2600. return ret;
  2601. }
  2602. static int vmw_cmd_check_not_3d(struct vmw_private *dev_priv,
  2603. struct vmw_sw_context *sw_context,
  2604. void *buf, uint32_t *size)
  2605. {
  2606. uint32_t size_remaining = *size;
  2607. uint32_t cmd_id;
  2608. cmd_id = ((uint32_t *)buf)[0];
  2609. switch (cmd_id) {
  2610. case SVGA_CMD_UPDATE:
  2611. *size = sizeof(uint32_t) + sizeof(SVGAFifoCmdUpdate);
  2612. break;
  2613. case SVGA_CMD_DEFINE_GMRFB:
  2614. *size = sizeof(uint32_t) + sizeof(SVGAFifoCmdDefineGMRFB);
  2615. break;
  2616. case SVGA_CMD_BLIT_GMRFB_TO_SCREEN:
  2617. *size = sizeof(uint32_t) + sizeof(SVGAFifoCmdBlitGMRFBToScreen);
  2618. break;
  2619. case SVGA_CMD_BLIT_SCREEN_TO_GMRFB:
  2620. *size = sizeof(uint32_t) + sizeof(SVGAFifoCmdBlitGMRFBToScreen);
  2621. break;
  2622. default:
  2623. DRM_ERROR("Unsupported SVGA command: %u.\n", cmd_id);
  2624. return -EINVAL;
  2625. }
  2626. if (*size > size_remaining) {
  2627. DRM_ERROR("Invalid SVGA command (size mismatch):"
  2628. " %u.\n", cmd_id);
  2629. return -EINVAL;
  2630. }
  2631. if (unlikely(!sw_context->kernel)) {
  2632. DRM_ERROR("Kernel only SVGA command: %u.\n", cmd_id);
  2633. return -EPERM;
  2634. }
  2635. if (cmd_id == SVGA_CMD_DEFINE_GMRFB)
  2636. return vmw_cmd_check_define_gmrfb(dev_priv, sw_context, buf);
  2637. return 0;
  2638. }
  2639. static const struct vmw_cmd_entry vmw_cmd_entries[SVGA_3D_CMD_MAX] = {
  2640. VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_DEFINE, &vmw_cmd_invalid,
  2641. false, false, false),
  2642. VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_DESTROY, &vmw_cmd_invalid,
  2643. false, false, false),
  2644. VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_COPY, &vmw_cmd_surface_copy_check,
  2645. true, false, false),
  2646. VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_STRETCHBLT, &vmw_cmd_stretch_blt_check,
  2647. true, false, false),
  2648. VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_DMA, &vmw_cmd_dma,
  2649. true, false, false),
  2650. VMW_CMD_DEF(SVGA_3D_CMD_CONTEXT_DEFINE, &vmw_cmd_invalid,
  2651. false, false, false),
  2652. VMW_CMD_DEF(SVGA_3D_CMD_CONTEXT_DESTROY, &vmw_cmd_invalid,
  2653. false, false, false),
  2654. VMW_CMD_DEF(SVGA_3D_CMD_SETTRANSFORM, &vmw_cmd_cid_check,
  2655. true, false, false),
  2656. VMW_CMD_DEF(SVGA_3D_CMD_SETZRANGE, &vmw_cmd_cid_check,
  2657. true, false, false),
  2658. VMW_CMD_DEF(SVGA_3D_CMD_SETRENDERSTATE, &vmw_cmd_cid_check,
  2659. true, false, false),
  2660. VMW_CMD_DEF(SVGA_3D_CMD_SETRENDERTARGET,
  2661. &vmw_cmd_set_render_target_check, true, false, false),
  2662. VMW_CMD_DEF(SVGA_3D_CMD_SETTEXTURESTATE, &vmw_cmd_tex_state,
  2663. true, false, false),
  2664. VMW_CMD_DEF(SVGA_3D_CMD_SETMATERIAL, &vmw_cmd_cid_check,
  2665. true, false, false),
  2666. VMW_CMD_DEF(SVGA_3D_CMD_SETLIGHTDATA, &vmw_cmd_cid_check,
  2667. true, false, false),
  2668. VMW_CMD_DEF(SVGA_3D_CMD_SETLIGHTENABLED, &vmw_cmd_cid_check,
  2669. true, false, false),
  2670. VMW_CMD_DEF(SVGA_3D_CMD_SETVIEWPORT, &vmw_cmd_cid_check,
  2671. true, false, false),
  2672. VMW_CMD_DEF(SVGA_3D_CMD_SETCLIPPLANE, &vmw_cmd_cid_check,
  2673. true, false, false),
  2674. VMW_CMD_DEF(SVGA_3D_CMD_CLEAR, &vmw_cmd_cid_check,
  2675. true, false, false),
  2676. VMW_CMD_DEF(SVGA_3D_CMD_PRESENT, &vmw_cmd_present_check,
  2677. false, false, false),
  2678. VMW_CMD_DEF(SVGA_3D_CMD_SHADER_DEFINE, &vmw_cmd_shader_define,
  2679. true, false, false),
  2680. VMW_CMD_DEF(SVGA_3D_CMD_SHADER_DESTROY, &vmw_cmd_shader_destroy,
  2681. true, false, false),
  2682. VMW_CMD_DEF(SVGA_3D_CMD_SET_SHADER, &vmw_cmd_set_shader,
  2683. true, false, false),
  2684. VMW_CMD_DEF(SVGA_3D_CMD_SET_SHADER_CONST, &vmw_cmd_set_shader_const,
  2685. true, false, false),
  2686. VMW_CMD_DEF(SVGA_3D_CMD_DRAW_PRIMITIVES, &vmw_cmd_draw,
  2687. true, false, false),
  2688. VMW_CMD_DEF(SVGA_3D_CMD_SETSCISSORRECT, &vmw_cmd_cid_check,
  2689. true, false, false),
  2690. VMW_CMD_DEF(SVGA_3D_CMD_BEGIN_QUERY, &vmw_cmd_begin_query,
  2691. true, false, false),
  2692. VMW_CMD_DEF(SVGA_3D_CMD_END_QUERY, &vmw_cmd_end_query,
  2693. true, false, false),
  2694. VMW_CMD_DEF(SVGA_3D_CMD_WAIT_FOR_QUERY, &vmw_cmd_wait_query,
  2695. true, false, false),
  2696. VMW_CMD_DEF(SVGA_3D_CMD_PRESENT_READBACK, &vmw_cmd_ok,
  2697. true, false, false),
  2698. VMW_CMD_DEF(SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN,
  2699. &vmw_cmd_blt_surf_screen_check, false, false, false),
  2700. VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_DEFINE_V2, &vmw_cmd_invalid,
  2701. false, false, false),
  2702. VMW_CMD_DEF(SVGA_3D_CMD_GENERATE_MIPMAPS, &vmw_cmd_invalid,
  2703. false, false, false),
  2704. VMW_CMD_DEF(SVGA_3D_CMD_ACTIVATE_SURFACE, &vmw_cmd_invalid,
  2705. false, false, false),
  2706. VMW_CMD_DEF(SVGA_3D_CMD_DEACTIVATE_SURFACE, &vmw_cmd_invalid,
  2707. false, false, false),
  2708. VMW_CMD_DEF(SVGA_3D_CMD_SCREEN_DMA, &vmw_cmd_invalid,
  2709. false, false, false),
  2710. VMW_CMD_DEF(SVGA_3D_CMD_SET_UNITY_SURFACE_COOKIE, &vmw_cmd_invalid,
  2711. false, false, false),
  2712. VMW_CMD_DEF(SVGA_3D_CMD_OPEN_CONTEXT_SURFACE, &vmw_cmd_invalid,
  2713. false, false, false),
  2714. VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_BITBLT, &vmw_cmd_invalid,
  2715. false, false, false),
  2716. VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_TRANSBLT, &vmw_cmd_invalid,
  2717. false, false, false),
  2718. VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_STRETCHBLT, &vmw_cmd_invalid,
  2719. false, false, false),
  2720. VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_COLORFILL, &vmw_cmd_invalid,
  2721. false, false, false),
  2722. VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_ALPHABLEND, &vmw_cmd_invalid,
  2723. false, false, false),
  2724. VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_CLEARTYPEBLEND, &vmw_cmd_invalid,
  2725. false, false, false),
  2726. VMW_CMD_DEF(SVGA_3D_CMD_SET_OTABLE_BASE, &vmw_cmd_invalid,
  2727. false, false, true),
  2728. VMW_CMD_DEF(SVGA_3D_CMD_READBACK_OTABLE, &vmw_cmd_invalid,
  2729. false, false, true),
  2730. VMW_CMD_DEF(SVGA_3D_CMD_DEFINE_GB_MOB, &vmw_cmd_invalid,
  2731. false, false, true),
  2732. VMW_CMD_DEF(SVGA_3D_CMD_DESTROY_GB_MOB, &vmw_cmd_invalid,
  2733. false, false, true),
  2734. VMW_CMD_DEF(SVGA_3D_CMD_REDEFINE_GB_MOB64, &vmw_cmd_invalid,
  2735. false, false, true),
  2736. VMW_CMD_DEF(SVGA_3D_CMD_UPDATE_GB_MOB_MAPPING, &vmw_cmd_invalid,
  2737. false, false, true),
  2738. VMW_CMD_DEF(SVGA_3D_CMD_DEFINE_GB_SURFACE, &vmw_cmd_invalid,
  2739. false, false, true),
  2740. VMW_CMD_DEF(SVGA_3D_CMD_DESTROY_GB_SURFACE, &vmw_cmd_invalid,
  2741. false, false, true),
  2742. VMW_CMD_DEF(SVGA_3D_CMD_BIND_GB_SURFACE, &vmw_cmd_bind_gb_surface,
  2743. true, false, true),
  2744. VMW_CMD_DEF(SVGA_3D_CMD_COND_BIND_GB_SURFACE, &vmw_cmd_invalid,
  2745. false, false, true),
  2746. VMW_CMD_DEF(SVGA_3D_CMD_UPDATE_GB_IMAGE, &vmw_cmd_update_gb_image,
  2747. true, false, true),
  2748. VMW_CMD_DEF(SVGA_3D_CMD_UPDATE_GB_SURFACE,
  2749. &vmw_cmd_update_gb_surface, true, false, true),
  2750. VMW_CMD_DEF(SVGA_3D_CMD_READBACK_GB_IMAGE,
  2751. &vmw_cmd_readback_gb_image, true, false, true),
  2752. VMW_CMD_DEF(SVGA_3D_CMD_READBACK_GB_SURFACE,
  2753. &vmw_cmd_readback_gb_surface, true, false, true),
  2754. VMW_CMD_DEF(SVGA_3D_CMD_INVALIDATE_GB_IMAGE,
  2755. &vmw_cmd_invalidate_gb_image, true, false, true),
  2756. VMW_CMD_DEF(SVGA_3D_CMD_INVALIDATE_GB_SURFACE,
  2757. &vmw_cmd_invalidate_gb_surface, true, false, true),
  2758. VMW_CMD_DEF(SVGA_3D_CMD_DEFINE_GB_CONTEXT, &vmw_cmd_invalid,
  2759. false, false, true),
  2760. VMW_CMD_DEF(SVGA_3D_CMD_DESTROY_GB_CONTEXT, &vmw_cmd_invalid,
  2761. false, false, true),
  2762. VMW_CMD_DEF(SVGA_3D_CMD_BIND_GB_CONTEXT, &vmw_cmd_invalid,
  2763. false, false, true),
  2764. VMW_CMD_DEF(SVGA_3D_CMD_READBACK_GB_CONTEXT, &vmw_cmd_invalid,
  2765. false, false, true),
  2766. VMW_CMD_DEF(SVGA_3D_CMD_INVALIDATE_GB_CONTEXT, &vmw_cmd_invalid,
  2767. false, false, true),
  2768. VMW_CMD_DEF(SVGA_3D_CMD_DEFINE_GB_SHADER, &vmw_cmd_invalid,
  2769. false, false, true),
  2770. VMW_CMD_DEF(SVGA_3D_CMD_BIND_GB_SHADER, &vmw_cmd_bind_gb_shader,
  2771. true, false, true),
  2772. VMW_CMD_DEF(SVGA_3D_CMD_DESTROY_GB_SHADER, &vmw_cmd_invalid,
  2773. false, false, true),
  2774. VMW_CMD_DEF(SVGA_3D_CMD_SET_OTABLE_BASE64, &vmw_cmd_invalid,
  2775. false, false, false),
  2776. VMW_CMD_DEF(SVGA_3D_CMD_BEGIN_GB_QUERY, &vmw_cmd_begin_gb_query,
  2777. true, false, true),
  2778. VMW_CMD_DEF(SVGA_3D_CMD_END_GB_QUERY, &vmw_cmd_end_gb_query,
  2779. true, false, true),
  2780. VMW_CMD_DEF(SVGA_3D_CMD_WAIT_FOR_GB_QUERY, &vmw_cmd_wait_gb_query,
  2781. true, false, true),
  2782. VMW_CMD_DEF(SVGA_3D_CMD_NOP, &vmw_cmd_ok,
  2783. true, false, true),
  2784. VMW_CMD_DEF(SVGA_3D_CMD_ENABLE_GART, &vmw_cmd_invalid,
  2785. false, false, true),
  2786. VMW_CMD_DEF(SVGA_3D_CMD_DISABLE_GART, &vmw_cmd_invalid,
  2787. false, false, true),
  2788. VMW_CMD_DEF(SVGA_3D_CMD_MAP_MOB_INTO_GART, &vmw_cmd_invalid,
  2789. false, false, true),
  2790. VMW_CMD_DEF(SVGA_3D_CMD_UNMAP_GART_RANGE, &vmw_cmd_invalid,
  2791. false, false, true),
  2792. VMW_CMD_DEF(SVGA_3D_CMD_DEFINE_GB_SCREENTARGET, &vmw_cmd_invalid,
  2793. false, false, true),
  2794. VMW_CMD_DEF(SVGA_3D_CMD_DESTROY_GB_SCREENTARGET, &vmw_cmd_invalid,
  2795. false, false, true),
  2796. VMW_CMD_DEF(SVGA_3D_CMD_BIND_GB_SCREENTARGET, &vmw_cmd_invalid,
  2797. false, false, true),
  2798. VMW_CMD_DEF(SVGA_3D_CMD_UPDATE_GB_SCREENTARGET, &vmw_cmd_invalid,
  2799. false, false, true),
  2800. VMW_CMD_DEF(SVGA_3D_CMD_READBACK_GB_IMAGE_PARTIAL, &vmw_cmd_invalid,
  2801. false, false, true),
  2802. VMW_CMD_DEF(SVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL, &vmw_cmd_invalid,
  2803. false, false, true),
  2804. VMW_CMD_DEF(SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE, &vmw_cmd_cid_check,
  2805. true, false, true),
  2806. VMW_CMD_DEF(SVGA_3D_CMD_GB_SCREEN_DMA, &vmw_cmd_invalid,
  2807. false, false, true),
  2808. VMW_CMD_DEF(SVGA_3D_CMD_BIND_GB_SURFACE_WITH_PITCH, &vmw_cmd_invalid,
  2809. false, false, true),
  2810. VMW_CMD_DEF(SVGA_3D_CMD_GB_MOB_FENCE, &vmw_cmd_invalid,
  2811. false, false, true),
  2812. VMW_CMD_DEF(SVGA_3D_CMD_DEFINE_GB_SURFACE_V2, &vmw_cmd_invalid,
  2813. false, false, true),
  2814. /*
  2815. * DX commands
  2816. */
  2817. VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_CONTEXT, &vmw_cmd_invalid,
  2818. false, false, true),
  2819. VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_CONTEXT, &vmw_cmd_invalid,
  2820. false, false, true),
  2821. VMW_CMD_DEF(SVGA_3D_CMD_DX_BIND_CONTEXT, &vmw_cmd_invalid,
  2822. false, false, true),
  2823. VMW_CMD_DEF(SVGA_3D_CMD_DX_READBACK_CONTEXT, &vmw_cmd_invalid,
  2824. false, false, true),
  2825. VMW_CMD_DEF(SVGA_3D_CMD_DX_INVALIDATE_CONTEXT, &vmw_cmd_invalid,
  2826. false, false, true),
  2827. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_SINGLE_CONSTANT_BUFFER,
  2828. &vmw_cmd_dx_set_single_constant_buffer, true, false, true),
  2829. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_SHADER_RESOURCES,
  2830. &vmw_cmd_dx_set_shader_res, true, false, true),
  2831. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_SHADER, &vmw_cmd_dx_set_shader,
  2832. true, false, true),
  2833. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_SAMPLERS, &vmw_cmd_dx_cid_check,
  2834. true, false, true),
  2835. VMW_CMD_DEF(SVGA_3D_CMD_DX_DRAW, &vmw_cmd_dx_cid_check,
  2836. true, false, true),
  2837. VMW_CMD_DEF(SVGA_3D_CMD_DX_DRAW_INDEXED, &vmw_cmd_dx_cid_check,
  2838. true, false, true),
  2839. VMW_CMD_DEF(SVGA_3D_CMD_DX_DRAW_INSTANCED, &vmw_cmd_dx_cid_check,
  2840. true, false, true),
  2841. VMW_CMD_DEF(SVGA_3D_CMD_DX_DRAW_INDEXED_INSTANCED,
  2842. &vmw_cmd_dx_cid_check, true, false, true),
  2843. VMW_CMD_DEF(SVGA_3D_CMD_DX_DRAW_AUTO, &vmw_cmd_dx_cid_check,
  2844. true, false, true),
  2845. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_VERTEX_BUFFERS,
  2846. &vmw_cmd_dx_set_vertex_buffers, true, false, true),
  2847. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_INDEX_BUFFER,
  2848. &vmw_cmd_dx_set_index_buffer, true, false, true),
  2849. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_RENDERTARGETS,
  2850. &vmw_cmd_dx_set_rendertargets, true, false, true),
  2851. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_BLEND_STATE, &vmw_cmd_dx_cid_check,
  2852. true, false, true),
  2853. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_DEPTHSTENCIL_STATE,
  2854. &vmw_cmd_dx_cid_check, true, false, true),
  2855. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_RASTERIZER_STATE,
  2856. &vmw_cmd_dx_cid_check, true, false, true),
  2857. VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_QUERY, &vmw_cmd_dx_define_query,
  2858. true, false, true),
  2859. VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_QUERY, &vmw_cmd_ok,
  2860. true, false, true),
  2861. VMW_CMD_DEF(SVGA_3D_CMD_DX_BIND_QUERY, &vmw_cmd_dx_bind_query,
  2862. true, false, true),
  2863. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_QUERY_OFFSET,
  2864. &vmw_cmd_ok, true, false, true),
  2865. VMW_CMD_DEF(SVGA_3D_CMD_DX_BEGIN_QUERY, &vmw_cmd_ok,
  2866. true, false, true),
  2867. VMW_CMD_DEF(SVGA_3D_CMD_DX_END_QUERY, &vmw_cmd_ok,
  2868. true, false, true),
  2869. VMW_CMD_DEF(SVGA_3D_CMD_DX_READBACK_QUERY, &vmw_cmd_invalid,
  2870. true, false, true),
  2871. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_PREDICATION, &vmw_cmd_invalid,
  2872. true, false, true),
  2873. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_VIEWPORTS, &vmw_cmd_dx_cid_check,
  2874. true, false, true),
  2875. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_SCISSORRECTS, &vmw_cmd_dx_cid_check,
  2876. true, false, true),
  2877. VMW_CMD_DEF(SVGA_3D_CMD_DX_CLEAR_RENDERTARGET_VIEW,
  2878. &vmw_cmd_dx_clear_rendertarget_view, true, false, true),
  2879. VMW_CMD_DEF(SVGA_3D_CMD_DX_CLEAR_DEPTHSTENCIL_VIEW,
  2880. &vmw_cmd_dx_clear_depthstencil_view, true, false, true),
  2881. VMW_CMD_DEF(SVGA_3D_CMD_DX_PRED_COPY, &vmw_cmd_invalid,
  2882. true, false, true),
  2883. VMW_CMD_DEF(SVGA_3D_CMD_DX_GENMIPS, &vmw_cmd_invalid,
  2884. true, false, true),
  2885. VMW_CMD_DEF(SVGA_3D_CMD_DX_UPDATE_SUBRESOURCE,
  2886. &vmw_cmd_dx_check_subresource, true, false, true),
  2887. VMW_CMD_DEF(SVGA_3D_CMD_DX_READBACK_SUBRESOURCE,
  2888. &vmw_cmd_dx_check_subresource, true, false, true),
  2889. VMW_CMD_DEF(SVGA_3D_CMD_DX_INVALIDATE_SUBRESOURCE,
  2890. &vmw_cmd_dx_check_subresource, true, false, true),
  2891. VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW,
  2892. &vmw_cmd_dx_view_define, true, false, true),
  2893. VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_SHADERRESOURCE_VIEW,
  2894. &vmw_cmd_dx_view_remove, true, false, true),
  2895. VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_RENDERTARGET_VIEW,
  2896. &vmw_cmd_dx_view_define, true, false, true),
  2897. VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_RENDERTARGET_VIEW,
  2898. &vmw_cmd_dx_view_remove, true, false, true),
  2899. VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW,
  2900. &vmw_cmd_dx_view_define, true, false, true),
  2901. VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_VIEW,
  2902. &vmw_cmd_dx_view_remove, true, false, true),
  2903. VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT,
  2904. &vmw_cmd_dx_so_define, true, false, true),
  2905. VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_ELEMENTLAYOUT,
  2906. &vmw_cmd_dx_cid_check, true, false, true),
  2907. VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_BLEND_STATE,
  2908. &vmw_cmd_dx_so_define, true, false, true),
  2909. VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_BLEND_STATE,
  2910. &vmw_cmd_dx_cid_check, true, false, true),
  2911. VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_STATE,
  2912. &vmw_cmd_dx_so_define, true, false, true),
  2913. VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_STATE,
  2914. &vmw_cmd_dx_cid_check, true, false, true),
  2915. VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE,
  2916. &vmw_cmd_dx_so_define, true, false, true),
  2917. VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_RASTERIZER_STATE,
  2918. &vmw_cmd_dx_cid_check, true, false, true),
  2919. VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_SAMPLER_STATE,
  2920. &vmw_cmd_dx_so_define, true, false, true),
  2921. VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_SAMPLER_STATE,
  2922. &vmw_cmd_dx_cid_check, true, false, true),
  2923. VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_SHADER,
  2924. &vmw_cmd_dx_define_shader, true, false, true),
  2925. VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_SHADER,
  2926. &vmw_cmd_dx_destroy_shader, true, false, true),
  2927. VMW_CMD_DEF(SVGA_3D_CMD_DX_BIND_SHADER,
  2928. &vmw_cmd_dx_bind_shader, true, false, true),
  2929. VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT,
  2930. &vmw_cmd_dx_so_define, true, false, true),
  2931. VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT,
  2932. &vmw_cmd_dx_cid_check, true, false, true),
  2933. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_STREAMOUTPUT, &vmw_cmd_dx_cid_check,
  2934. true, false, true),
  2935. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_SOTARGETS,
  2936. &vmw_cmd_dx_set_so_targets, true, false, true),
  2937. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_INPUT_LAYOUT,
  2938. &vmw_cmd_dx_cid_check, true, false, true),
  2939. VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_TOPOLOGY,
  2940. &vmw_cmd_dx_cid_check, true, false, true),
  2941. VMW_CMD_DEF(SVGA_3D_CMD_DX_BUFFER_COPY,
  2942. &vmw_cmd_buffer_copy_check, true, false, true),
  2943. VMW_CMD_DEF(SVGA_3D_CMD_DX_PRED_COPY_REGION,
  2944. &vmw_cmd_pred_copy_check, true, false, true),
  2945. };
  2946. static int vmw_cmd_check(struct vmw_private *dev_priv,
  2947. struct vmw_sw_context *sw_context,
  2948. void *buf, uint32_t *size)
  2949. {
  2950. uint32_t cmd_id;
  2951. uint32_t size_remaining = *size;
  2952. SVGA3dCmdHeader *header = (SVGA3dCmdHeader *) buf;
  2953. int ret;
  2954. const struct vmw_cmd_entry *entry;
  2955. bool gb = dev_priv->capabilities & SVGA_CAP_GBOBJECTS;
  2956. cmd_id = ((uint32_t *)buf)[0];
  2957. /* Handle any none 3D commands */
  2958. if (unlikely(cmd_id < SVGA_CMD_MAX))
  2959. return vmw_cmd_check_not_3d(dev_priv, sw_context, buf, size);
  2960. cmd_id = header->id;
  2961. *size = header->size + sizeof(SVGA3dCmdHeader);
  2962. cmd_id -= SVGA_3D_CMD_BASE;
  2963. if (unlikely(*size > size_remaining))
  2964. goto out_invalid;
  2965. if (unlikely(cmd_id >= SVGA_3D_CMD_MAX - SVGA_3D_CMD_BASE))
  2966. goto out_invalid;
  2967. entry = &vmw_cmd_entries[cmd_id];
  2968. if (unlikely(!entry->func))
  2969. goto out_invalid;
  2970. if (unlikely(!entry->user_allow && !sw_context->kernel))
  2971. goto out_privileged;
  2972. if (unlikely(entry->gb_disable && gb))
  2973. goto out_old;
  2974. if (unlikely(entry->gb_enable && !gb))
  2975. goto out_new;
  2976. ret = entry->func(dev_priv, sw_context, header);
  2977. if (unlikely(ret != 0))
  2978. goto out_invalid;
  2979. return 0;
  2980. out_invalid:
  2981. DRM_ERROR("Invalid SVGA3D command: %d\n",
  2982. cmd_id + SVGA_3D_CMD_BASE);
  2983. return -EINVAL;
  2984. out_privileged:
  2985. DRM_ERROR("Privileged SVGA3D command: %d\n",
  2986. cmd_id + SVGA_3D_CMD_BASE);
  2987. return -EPERM;
  2988. out_old:
  2989. DRM_ERROR("Deprecated (disallowed) SVGA3D command: %d\n",
  2990. cmd_id + SVGA_3D_CMD_BASE);
  2991. return -EINVAL;
  2992. out_new:
  2993. DRM_ERROR("SVGA3D command: %d not supported by virtual hardware.\n",
  2994. cmd_id + SVGA_3D_CMD_BASE);
  2995. return -EINVAL;
  2996. }
  2997. static int vmw_cmd_check_all(struct vmw_private *dev_priv,
  2998. struct vmw_sw_context *sw_context,
  2999. void *buf,
  3000. uint32_t size)
  3001. {
  3002. int32_t cur_size = size;
  3003. int ret;
  3004. sw_context->buf_start = buf;
  3005. while (cur_size > 0) {
  3006. size = cur_size;
  3007. ret = vmw_cmd_check(dev_priv, sw_context, buf, &size);
  3008. if (unlikely(ret != 0))
  3009. return ret;
  3010. buf = (void *)((unsigned long) buf + size);
  3011. cur_size -= size;
  3012. }
  3013. if (unlikely(cur_size != 0)) {
  3014. DRM_ERROR("Command verifier out of sync.\n");
  3015. return -EINVAL;
  3016. }
  3017. return 0;
  3018. }
  3019. static void vmw_free_relocations(struct vmw_sw_context *sw_context)
  3020. {
  3021. sw_context->cur_reloc = 0;
  3022. }
  3023. static void vmw_apply_relocations(struct vmw_sw_context *sw_context)
  3024. {
  3025. uint32_t i;
  3026. struct vmw_relocation *reloc;
  3027. struct ttm_validate_buffer *validate;
  3028. struct ttm_buffer_object *bo;
  3029. for (i = 0; i < sw_context->cur_reloc; ++i) {
  3030. reloc = &sw_context->relocs[i];
  3031. validate = &sw_context->val_bufs[reloc->index].base;
  3032. bo = validate->bo;
  3033. switch (bo->mem.mem_type) {
  3034. case TTM_PL_VRAM:
  3035. reloc->location->offset += bo->offset;
  3036. reloc->location->gmrId = SVGA_GMR_FRAMEBUFFER;
  3037. break;
  3038. case VMW_PL_GMR:
  3039. reloc->location->gmrId = bo->mem.start;
  3040. break;
  3041. case VMW_PL_MOB:
  3042. *reloc->mob_loc = bo->mem.start;
  3043. break;
  3044. default:
  3045. BUG();
  3046. }
  3047. }
  3048. vmw_free_relocations(sw_context);
  3049. }
  3050. /**
  3051. * vmw_resource_list_unrefererence - Free up a resource list and unreference
  3052. * all resources referenced by it.
  3053. *
  3054. * @list: The resource list.
  3055. */
  3056. static void vmw_resource_list_unreference(struct vmw_sw_context *sw_context,
  3057. struct list_head *list)
  3058. {
  3059. struct vmw_resource_val_node *val, *val_next;
  3060. /*
  3061. * Drop references to resources held during command submission.
  3062. */
  3063. list_for_each_entry_safe(val, val_next, list, head) {
  3064. list_del_init(&val->head);
  3065. vmw_resource_unreference(&val->res);
  3066. if (val->staged_bindings) {
  3067. if (val->staged_bindings != sw_context->staged_bindings)
  3068. vmw_binding_state_free(val->staged_bindings);
  3069. else
  3070. sw_context->staged_bindings_inuse = false;
  3071. val->staged_bindings = NULL;
  3072. }
  3073. kfree(val);
  3074. }
  3075. }
  3076. static void vmw_clear_validations(struct vmw_sw_context *sw_context)
  3077. {
  3078. struct vmw_validate_buffer *entry, *next;
  3079. struct vmw_resource_val_node *val;
  3080. /*
  3081. * Drop references to DMA buffers held during command submission.
  3082. */
  3083. list_for_each_entry_safe(entry, next, &sw_context->validate_nodes,
  3084. base.head) {
  3085. list_del(&entry->base.head);
  3086. ttm_bo_unref(&entry->base.bo);
  3087. (void) drm_ht_remove_item(&sw_context->res_ht, &entry->hash);
  3088. sw_context->cur_val_buf--;
  3089. }
  3090. BUG_ON(sw_context->cur_val_buf != 0);
  3091. list_for_each_entry(val, &sw_context->resource_list, head)
  3092. (void) drm_ht_remove_item(&sw_context->res_ht, &val->hash);
  3093. }
  3094. int vmw_validate_single_buffer(struct vmw_private *dev_priv,
  3095. struct ttm_buffer_object *bo,
  3096. bool interruptible,
  3097. bool validate_as_mob)
  3098. {
  3099. struct vmw_dma_buffer *vbo = container_of(bo, struct vmw_dma_buffer,
  3100. base);
  3101. int ret;
  3102. if (vbo->pin_count > 0)
  3103. return 0;
  3104. if (validate_as_mob)
  3105. return ttm_bo_validate(bo, &vmw_mob_placement, interruptible,
  3106. false);
  3107. /**
  3108. * Put BO in VRAM if there is space, otherwise as a GMR.
  3109. * If there is no space in VRAM and GMR ids are all used up,
  3110. * start evicting GMRs to make room. If the DMA buffer can't be
  3111. * used as a GMR, this will return -ENOMEM.
  3112. */
  3113. ret = ttm_bo_validate(bo, &vmw_vram_gmr_placement, interruptible,
  3114. false);
  3115. if (likely(ret == 0 || ret == -ERESTARTSYS))
  3116. return ret;
  3117. /**
  3118. * If that failed, try VRAM again, this time evicting
  3119. * previous contents.
  3120. */
  3121. ret = ttm_bo_validate(bo, &vmw_vram_placement, interruptible, false);
  3122. return ret;
  3123. }
  3124. static int vmw_validate_buffers(struct vmw_private *dev_priv,
  3125. struct vmw_sw_context *sw_context)
  3126. {
  3127. struct vmw_validate_buffer *entry;
  3128. int ret;
  3129. list_for_each_entry(entry, &sw_context->validate_nodes, base.head) {
  3130. ret = vmw_validate_single_buffer(dev_priv, entry->base.bo,
  3131. true,
  3132. entry->validate_as_mob);
  3133. if (unlikely(ret != 0))
  3134. return ret;
  3135. }
  3136. return 0;
  3137. }
  3138. static int vmw_resize_cmd_bounce(struct vmw_sw_context *sw_context,
  3139. uint32_t size)
  3140. {
  3141. if (likely(sw_context->cmd_bounce_size >= size))
  3142. return 0;
  3143. if (sw_context->cmd_bounce_size == 0)
  3144. sw_context->cmd_bounce_size = VMWGFX_CMD_BOUNCE_INIT_SIZE;
  3145. while (sw_context->cmd_bounce_size < size) {
  3146. sw_context->cmd_bounce_size =
  3147. PAGE_ALIGN(sw_context->cmd_bounce_size +
  3148. (sw_context->cmd_bounce_size >> 1));
  3149. }
  3150. if (sw_context->cmd_bounce != NULL)
  3151. vfree(sw_context->cmd_bounce);
  3152. sw_context->cmd_bounce = vmalloc(sw_context->cmd_bounce_size);
  3153. if (sw_context->cmd_bounce == NULL) {
  3154. DRM_ERROR("Failed to allocate command bounce buffer.\n");
  3155. sw_context->cmd_bounce_size = 0;
  3156. return -ENOMEM;
  3157. }
  3158. return 0;
  3159. }
  3160. /**
  3161. * vmw_execbuf_fence_commands - create and submit a command stream fence
  3162. *
  3163. * Creates a fence object and submits a command stream marker.
  3164. * If this fails for some reason, We sync the fifo and return NULL.
  3165. * It is then safe to fence buffers with a NULL pointer.
  3166. *
  3167. * If @p_handle is not NULL @file_priv must also not be NULL. Creates
  3168. * a userspace handle if @p_handle is not NULL, otherwise not.
  3169. */
  3170. int vmw_execbuf_fence_commands(struct drm_file *file_priv,
  3171. struct vmw_private *dev_priv,
  3172. struct vmw_fence_obj **p_fence,
  3173. uint32_t *p_handle)
  3174. {
  3175. uint32_t sequence;
  3176. int ret;
  3177. bool synced = false;
  3178. /* p_handle implies file_priv. */
  3179. BUG_ON(p_handle != NULL && file_priv == NULL);
  3180. ret = vmw_fifo_send_fence(dev_priv, &sequence);
  3181. if (unlikely(ret != 0)) {
  3182. DRM_ERROR("Fence submission error. Syncing.\n");
  3183. synced = true;
  3184. }
  3185. if (p_handle != NULL)
  3186. ret = vmw_user_fence_create(file_priv, dev_priv->fman,
  3187. sequence, p_fence, p_handle);
  3188. else
  3189. ret = vmw_fence_create(dev_priv->fman, sequence, p_fence);
  3190. if (unlikely(ret != 0 && !synced)) {
  3191. (void) vmw_fallback_wait(dev_priv, false, false,
  3192. sequence, false,
  3193. VMW_FENCE_WAIT_TIMEOUT);
  3194. *p_fence = NULL;
  3195. }
  3196. return 0;
  3197. }
  3198. /**
  3199. * vmw_execbuf_copy_fence_user - copy fence object information to
  3200. * user-space.
  3201. *
  3202. * @dev_priv: Pointer to a vmw_private struct.
  3203. * @vmw_fp: Pointer to the struct vmw_fpriv representing the calling file.
  3204. * @ret: Return value from fence object creation.
  3205. * @user_fence_rep: User space address of a struct drm_vmw_fence_rep to
  3206. * which the information should be copied.
  3207. * @fence: Pointer to the fenc object.
  3208. * @fence_handle: User-space fence handle.
  3209. *
  3210. * This function copies fence information to user-space. If copying fails,
  3211. * The user-space struct drm_vmw_fence_rep::error member is hopefully
  3212. * left untouched, and if it's preloaded with an -EFAULT by user-space,
  3213. * the error will hopefully be detected.
  3214. * Also if copying fails, user-space will be unable to signal the fence
  3215. * object so we wait for it immediately, and then unreference the
  3216. * user-space reference.
  3217. */
  3218. void
  3219. vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
  3220. struct vmw_fpriv *vmw_fp,
  3221. int ret,
  3222. struct drm_vmw_fence_rep __user *user_fence_rep,
  3223. struct vmw_fence_obj *fence,
  3224. uint32_t fence_handle)
  3225. {
  3226. struct drm_vmw_fence_rep fence_rep;
  3227. if (user_fence_rep == NULL)
  3228. return;
  3229. memset(&fence_rep, 0, sizeof(fence_rep));
  3230. fence_rep.error = ret;
  3231. if (ret == 0) {
  3232. BUG_ON(fence == NULL);
  3233. fence_rep.handle = fence_handle;
  3234. fence_rep.seqno = fence->base.seqno;
  3235. vmw_update_seqno(dev_priv, &dev_priv->fifo);
  3236. fence_rep.passed_seqno = dev_priv->last_read_seqno;
  3237. }
  3238. /*
  3239. * copy_to_user errors will be detected by user space not
  3240. * seeing fence_rep::error filled in. Typically
  3241. * user-space would have pre-set that member to -EFAULT.
  3242. */
  3243. ret = copy_to_user(user_fence_rep, &fence_rep,
  3244. sizeof(fence_rep));
  3245. /*
  3246. * User-space lost the fence object. We need to sync
  3247. * and unreference the handle.
  3248. */
  3249. if (unlikely(ret != 0) && (fence_rep.error == 0)) {
  3250. ttm_ref_object_base_unref(vmw_fp->tfile,
  3251. fence_handle, TTM_REF_USAGE);
  3252. DRM_ERROR("Fence copy error. Syncing.\n");
  3253. (void) vmw_fence_obj_wait(fence, false, false,
  3254. VMW_FENCE_WAIT_TIMEOUT);
  3255. }
  3256. }
  3257. /**
  3258. * vmw_execbuf_submit_fifo - Patch a command batch and submit it using
  3259. * the fifo.
  3260. *
  3261. * @dev_priv: Pointer to a device private structure.
  3262. * @kernel_commands: Pointer to the unpatched command batch.
  3263. * @command_size: Size of the unpatched command batch.
  3264. * @sw_context: Structure holding the relocation lists.
  3265. *
  3266. * Side effects: If this function returns 0, then the command batch
  3267. * pointed to by @kernel_commands will have been modified.
  3268. */
  3269. static int vmw_execbuf_submit_fifo(struct vmw_private *dev_priv,
  3270. void *kernel_commands,
  3271. u32 command_size,
  3272. struct vmw_sw_context *sw_context)
  3273. {
  3274. void *cmd;
  3275. if (sw_context->dx_ctx_node)
  3276. cmd = vmw_fifo_reserve_dx(dev_priv, command_size,
  3277. sw_context->dx_ctx_node->res->id);
  3278. else
  3279. cmd = vmw_fifo_reserve(dev_priv, command_size);
  3280. if (!cmd) {
  3281. DRM_ERROR("Failed reserving fifo space for commands.\n");
  3282. return -ENOMEM;
  3283. }
  3284. vmw_apply_relocations(sw_context);
  3285. memcpy(cmd, kernel_commands, command_size);
  3286. vmw_resource_relocations_apply(cmd, &sw_context->res_relocations);
  3287. vmw_resource_relocations_free(&sw_context->res_relocations);
  3288. vmw_fifo_commit(dev_priv, command_size);
  3289. return 0;
  3290. }
  3291. /**
  3292. * vmw_execbuf_submit_cmdbuf - Patch a command batch and submit it using
  3293. * the command buffer manager.
  3294. *
  3295. * @dev_priv: Pointer to a device private structure.
  3296. * @header: Opaque handle to the command buffer allocation.
  3297. * @command_size: Size of the unpatched command batch.
  3298. * @sw_context: Structure holding the relocation lists.
  3299. *
  3300. * Side effects: If this function returns 0, then the command buffer
  3301. * represented by @header will have been modified.
  3302. */
  3303. static int vmw_execbuf_submit_cmdbuf(struct vmw_private *dev_priv,
  3304. struct vmw_cmdbuf_header *header,
  3305. u32 command_size,
  3306. struct vmw_sw_context *sw_context)
  3307. {
  3308. u32 id = ((sw_context->dx_ctx_node) ? sw_context->dx_ctx_node->res->id :
  3309. SVGA3D_INVALID_ID);
  3310. void *cmd = vmw_cmdbuf_reserve(dev_priv->cman, command_size,
  3311. id, false, header);
  3312. vmw_apply_relocations(sw_context);
  3313. vmw_resource_relocations_apply(cmd, &sw_context->res_relocations);
  3314. vmw_resource_relocations_free(&sw_context->res_relocations);
  3315. vmw_cmdbuf_commit(dev_priv->cman, command_size, header, false);
  3316. return 0;
  3317. }
  3318. /**
  3319. * vmw_execbuf_cmdbuf - Prepare, if possible, a user-space command batch for
  3320. * submission using a command buffer.
  3321. *
  3322. * @dev_priv: Pointer to a device private structure.
  3323. * @user_commands: User-space pointer to the commands to be submitted.
  3324. * @command_size: Size of the unpatched command batch.
  3325. * @header: Out parameter returning the opaque pointer to the command buffer.
  3326. *
  3327. * This function checks whether we can use the command buffer manager for
  3328. * submission and if so, creates a command buffer of suitable size and
  3329. * copies the user data into that buffer.
  3330. *
  3331. * On successful return, the function returns a pointer to the data in the
  3332. * command buffer and *@header is set to non-NULL.
  3333. * If command buffers could not be used, the function will return the value
  3334. * of @kernel_commands on function call. That value may be NULL. In that case,
  3335. * the value of *@header will be set to NULL.
  3336. * If an error is encountered, the function will return a pointer error value.
  3337. * If the function is interrupted by a signal while sleeping, it will return
  3338. * -ERESTARTSYS casted to a pointer error value.
  3339. */
  3340. static void *vmw_execbuf_cmdbuf(struct vmw_private *dev_priv,
  3341. void __user *user_commands,
  3342. void *kernel_commands,
  3343. u32 command_size,
  3344. struct vmw_cmdbuf_header **header)
  3345. {
  3346. size_t cmdbuf_size;
  3347. int ret;
  3348. *header = NULL;
  3349. if (!dev_priv->cman || kernel_commands)
  3350. return kernel_commands;
  3351. if (command_size > SVGA_CB_MAX_SIZE) {
  3352. DRM_ERROR("Command buffer is too large.\n");
  3353. return ERR_PTR(-EINVAL);
  3354. }
  3355. /* If possible, add a little space for fencing. */
  3356. cmdbuf_size = command_size + 512;
  3357. cmdbuf_size = min_t(size_t, cmdbuf_size, SVGA_CB_MAX_SIZE);
  3358. kernel_commands = vmw_cmdbuf_alloc(dev_priv->cman, cmdbuf_size,
  3359. true, header);
  3360. if (IS_ERR(kernel_commands))
  3361. return kernel_commands;
  3362. ret = copy_from_user(kernel_commands, user_commands,
  3363. command_size);
  3364. if (ret) {
  3365. DRM_ERROR("Failed copying commands.\n");
  3366. vmw_cmdbuf_header_free(*header);
  3367. *header = NULL;
  3368. return ERR_PTR(-EFAULT);
  3369. }
  3370. return kernel_commands;
  3371. }
  3372. static int vmw_execbuf_tie_context(struct vmw_private *dev_priv,
  3373. struct vmw_sw_context *sw_context,
  3374. uint32_t handle)
  3375. {
  3376. struct vmw_resource_val_node *ctx_node;
  3377. struct vmw_resource *res;
  3378. int ret;
  3379. if (handle == SVGA3D_INVALID_ID)
  3380. return 0;
  3381. ret = vmw_user_resource_lookup_handle(dev_priv, sw_context->fp->tfile,
  3382. handle, user_context_converter,
  3383. &res);
  3384. if (unlikely(ret != 0)) {
  3385. DRM_ERROR("Could not find or user DX context 0x%08x.\n",
  3386. (unsigned) handle);
  3387. return ret;
  3388. }
  3389. ret = vmw_resource_val_add(sw_context, res, &ctx_node);
  3390. if (unlikely(ret != 0))
  3391. goto out_err;
  3392. sw_context->dx_ctx_node = ctx_node;
  3393. sw_context->man = vmw_context_res_man(res);
  3394. out_err:
  3395. vmw_resource_unreference(&res);
  3396. return ret;
  3397. }
  3398. int vmw_execbuf_process(struct drm_file *file_priv,
  3399. struct vmw_private *dev_priv,
  3400. void __user *user_commands,
  3401. void *kernel_commands,
  3402. uint32_t command_size,
  3403. uint64_t throttle_us,
  3404. uint32_t dx_context_handle,
  3405. struct drm_vmw_fence_rep __user *user_fence_rep,
  3406. struct vmw_fence_obj **out_fence)
  3407. {
  3408. struct vmw_sw_context *sw_context = &dev_priv->ctx;
  3409. struct vmw_fence_obj *fence = NULL;
  3410. struct vmw_resource *error_resource;
  3411. struct list_head resource_list;
  3412. struct vmw_cmdbuf_header *header;
  3413. struct ww_acquire_ctx ticket;
  3414. uint32_t handle;
  3415. int ret;
  3416. if (throttle_us) {
  3417. ret = vmw_wait_lag(dev_priv, &dev_priv->fifo.marker_queue,
  3418. throttle_us);
  3419. if (ret)
  3420. return ret;
  3421. }
  3422. kernel_commands = vmw_execbuf_cmdbuf(dev_priv, user_commands,
  3423. kernel_commands, command_size,
  3424. &header);
  3425. if (IS_ERR(kernel_commands))
  3426. return PTR_ERR(kernel_commands);
  3427. ret = mutex_lock_interruptible(&dev_priv->cmdbuf_mutex);
  3428. if (ret) {
  3429. ret = -ERESTARTSYS;
  3430. goto out_free_header;
  3431. }
  3432. sw_context->kernel = false;
  3433. if (kernel_commands == NULL) {
  3434. ret = vmw_resize_cmd_bounce(sw_context, command_size);
  3435. if (unlikely(ret != 0))
  3436. goto out_unlock;
  3437. ret = copy_from_user(sw_context->cmd_bounce,
  3438. user_commands, command_size);
  3439. if (unlikely(ret != 0)) {
  3440. ret = -EFAULT;
  3441. DRM_ERROR("Failed copying commands.\n");
  3442. goto out_unlock;
  3443. }
  3444. kernel_commands = sw_context->cmd_bounce;
  3445. } else if (!header)
  3446. sw_context->kernel = true;
  3447. sw_context->fp = vmw_fpriv(file_priv);
  3448. sw_context->cur_reloc = 0;
  3449. sw_context->cur_val_buf = 0;
  3450. INIT_LIST_HEAD(&sw_context->resource_list);
  3451. INIT_LIST_HEAD(&sw_context->ctx_resource_list);
  3452. sw_context->cur_query_bo = dev_priv->pinned_bo;
  3453. sw_context->last_query_ctx = NULL;
  3454. sw_context->needs_post_query_barrier = false;
  3455. sw_context->dx_ctx_node = NULL;
  3456. sw_context->dx_query_mob = NULL;
  3457. sw_context->dx_query_ctx = NULL;
  3458. memset(sw_context->res_cache, 0, sizeof(sw_context->res_cache));
  3459. INIT_LIST_HEAD(&sw_context->validate_nodes);
  3460. INIT_LIST_HEAD(&sw_context->res_relocations);
  3461. if (sw_context->staged_bindings)
  3462. vmw_binding_state_reset(sw_context->staged_bindings);
  3463. if (!sw_context->res_ht_initialized) {
  3464. ret = drm_ht_create(&sw_context->res_ht, VMW_RES_HT_ORDER);
  3465. if (unlikely(ret != 0))
  3466. goto out_unlock;
  3467. sw_context->res_ht_initialized = true;
  3468. }
  3469. INIT_LIST_HEAD(&sw_context->staged_cmd_res);
  3470. INIT_LIST_HEAD(&resource_list);
  3471. ret = vmw_execbuf_tie_context(dev_priv, sw_context, dx_context_handle);
  3472. if (unlikely(ret != 0)) {
  3473. list_splice_init(&sw_context->ctx_resource_list,
  3474. &sw_context->resource_list);
  3475. goto out_err_nores;
  3476. }
  3477. ret = vmw_cmd_check_all(dev_priv, sw_context, kernel_commands,
  3478. command_size);
  3479. /*
  3480. * Merge the resource lists before checking the return status
  3481. * from vmd_cmd_check_all so that all the open hashtabs will
  3482. * be handled properly even if vmw_cmd_check_all fails.
  3483. */
  3484. list_splice_init(&sw_context->ctx_resource_list,
  3485. &sw_context->resource_list);
  3486. if (unlikely(ret != 0))
  3487. goto out_err_nores;
  3488. ret = vmw_resources_reserve(sw_context);
  3489. if (unlikely(ret != 0))
  3490. goto out_err_nores;
  3491. ret = ttm_eu_reserve_buffers(&ticket, &sw_context->validate_nodes,
  3492. true, NULL);
  3493. if (unlikely(ret != 0))
  3494. goto out_err_nores;
  3495. ret = vmw_validate_buffers(dev_priv, sw_context);
  3496. if (unlikely(ret != 0))
  3497. goto out_err;
  3498. ret = vmw_resources_validate(sw_context);
  3499. if (unlikely(ret != 0))
  3500. goto out_err;
  3501. ret = mutex_lock_interruptible(&dev_priv->binding_mutex);
  3502. if (unlikely(ret != 0)) {
  3503. ret = -ERESTARTSYS;
  3504. goto out_err;
  3505. }
  3506. if (dev_priv->has_mob) {
  3507. ret = vmw_rebind_contexts(sw_context);
  3508. if (unlikely(ret != 0))
  3509. goto out_unlock_binding;
  3510. }
  3511. if (!header) {
  3512. ret = vmw_execbuf_submit_fifo(dev_priv, kernel_commands,
  3513. command_size, sw_context);
  3514. } else {
  3515. ret = vmw_execbuf_submit_cmdbuf(dev_priv, header, command_size,
  3516. sw_context);
  3517. header = NULL;
  3518. }
  3519. mutex_unlock(&dev_priv->binding_mutex);
  3520. if (ret)
  3521. goto out_err;
  3522. vmw_query_bo_switch_commit(dev_priv, sw_context);
  3523. ret = vmw_execbuf_fence_commands(file_priv, dev_priv,
  3524. &fence,
  3525. (user_fence_rep) ? &handle : NULL);
  3526. /*
  3527. * This error is harmless, because if fence submission fails,
  3528. * vmw_fifo_send_fence will sync. The error will be propagated to
  3529. * user-space in @fence_rep
  3530. */
  3531. if (ret != 0)
  3532. DRM_ERROR("Fence submission error. Syncing.\n");
  3533. vmw_resources_unreserve(sw_context, false);
  3534. ttm_eu_fence_buffer_objects(&ticket, &sw_context->validate_nodes,
  3535. (void *) fence);
  3536. if (unlikely(dev_priv->pinned_bo != NULL &&
  3537. !dev_priv->query_cid_valid))
  3538. __vmw_execbuf_release_pinned_bo(dev_priv, fence);
  3539. vmw_clear_validations(sw_context);
  3540. vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv), ret,
  3541. user_fence_rep, fence, handle);
  3542. /* Don't unreference when handing fence out */
  3543. if (unlikely(out_fence != NULL)) {
  3544. *out_fence = fence;
  3545. fence = NULL;
  3546. } else if (likely(fence != NULL)) {
  3547. vmw_fence_obj_unreference(&fence);
  3548. }
  3549. list_splice_init(&sw_context->resource_list, &resource_list);
  3550. vmw_cmdbuf_res_commit(&sw_context->staged_cmd_res);
  3551. mutex_unlock(&dev_priv->cmdbuf_mutex);
  3552. /*
  3553. * Unreference resources outside of the cmdbuf_mutex to
  3554. * avoid deadlocks in resource destruction paths.
  3555. */
  3556. vmw_resource_list_unreference(sw_context, &resource_list);
  3557. return 0;
  3558. out_unlock_binding:
  3559. mutex_unlock(&dev_priv->binding_mutex);
  3560. out_err:
  3561. ttm_eu_backoff_reservation(&ticket, &sw_context->validate_nodes);
  3562. out_err_nores:
  3563. vmw_resources_unreserve(sw_context, true);
  3564. vmw_resource_relocations_free(&sw_context->res_relocations);
  3565. vmw_free_relocations(sw_context);
  3566. vmw_clear_validations(sw_context);
  3567. if (unlikely(dev_priv->pinned_bo != NULL &&
  3568. !dev_priv->query_cid_valid))
  3569. __vmw_execbuf_release_pinned_bo(dev_priv, NULL);
  3570. out_unlock:
  3571. list_splice_init(&sw_context->resource_list, &resource_list);
  3572. error_resource = sw_context->error_resource;
  3573. sw_context->error_resource = NULL;
  3574. vmw_cmdbuf_res_revert(&sw_context->staged_cmd_res);
  3575. mutex_unlock(&dev_priv->cmdbuf_mutex);
  3576. /*
  3577. * Unreference resources outside of the cmdbuf_mutex to
  3578. * avoid deadlocks in resource destruction paths.
  3579. */
  3580. vmw_resource_list_unreference(sw_context, &resource_list);
  3581. if (unlikely(error_resource != NULL))
  3582. vmw_resource_unreference(&error_resource);
  3583. out_free_header:
  3584. if (header)
  3585. vmw_cmdbuf_header_free(header);
  3586. return ret;
  3587. }
  3588. /**
  3589. * vmw_execbuf_unpin_panic - Idle the fifo and unpin the query buffer.
  3590. *
  3591. * @dev_priv: The device private structure.
  3592. *
  3593. * This function is called to idle the fifo and unpin the query buffer
  3594. * if the normal way to do this hits an error, which should typically be
  3595. * extremely rare.
  3596. */
  3597. static void vmw_execbuf_unpin_panic(struct vmw_private *dev_priv)
  3598. {
  3599. DRM_ERROR("Can't unpin query buffer. Trying to recover.\n");
  3600. (void) vmw_fallback_wait(dev_priv, false, true, 0, false, 10*HZ);
  3601. vmw_bo_pin_reserved(dev_priv->pinned_bo, false);
  3602. if (dev_priv->dummy_query_bo_pinned) {
  3603. vmw_bo_pin_reserved(dev_priv->dummy_query_bo, false);
  3604. dev_priv->dummy_query_bo_pinned = false;
  3605. }
  3606. }
  3607. /**
  3608. * __vmw_execbuf_release_pinned_bo - Flush queries and unpin the pinned
  3609. * query bo.
  3610. *
  3611. * @dev_priv: The device private structure.
  3612. * @fence: If non-NULL should point to a struct vmw_fence_obj issued
  3613. * _after_ a query barrier that flushes all queries touching the current
  3614. * buffer pointed to by @dev_priv->pinned_bo
  3615. *
  3616. * This function should be used to unpin the pinned query bo, or
  3617. * as a query barrier when we need to make sure that all queries have
  3618. * finished before the next fifo command. (For example on hardware
  3619. * context destructions where the hardware may otherwise leak unfinished
  3620. * queries).
  3621. *
  3622. * This function does not return any failure codes, but make attempts
  3623. * to do safe unpinning in case of errors.
  3624. *
  3625. * The function will synchronize on the previous query barrier, and will
  3626. * thus not finish until that barrier has executed.
  3627. *
  3628. * the @dev_priv->cmdbuf_mutex needs to be held by the current thread
  3629. * before calling this function.
  3630. */
  3631. void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
  3632. struct vmw_fence_obj *fence)
  3633. {
  3634. int ret = 0;
  3635. struct list_head validate_list;
  3636. struct ttm_validate_buffer pinned_val, query_val;
  3637. struct vmw_fence_obj *lfence = NULL;
  3638. struct ww_acquire_ctx ticket;
  3639. if (dev_priv->pinned_bo == NULL)
  3640. goto out_unlock;
  3641. INIT_LIST_HEAD(&validate_list);
  3642. pinned_val.bo = ttm_bo_reference(&dev_priv->pinned_bo->base);
  3643. pinned_val.shared = false;
  3644. list_add_tail(&pinned_val.head, &validate_list);
  3645. query_val.bo = ttm_bo_reference(&dev_priv->dummy_query_bo->base);
  3646. query_val.shared = false;
  3647. list_add_tail(&query_val.head, &validate_list);
  3648. ret = ttm_eu_reserve_buffers(&ticket, &validate_list,
  3649. false, NULL);
  3650. if (unlikely(ret != 0)) {
  3651. vmw_execbuf_unpin_panic(dev_priv);
  3652. goto out_no_reserve;
  3653. }
  3654. if (dev_priv->query_cid_valid) {
  3655. BUG_ON(fence != NULL);
  3656. ret = vmw_fifo_emit_dummy_query(dev_priv, dev_priv->query_cid);
  3657. if (unlikely(ret != 0)) {
  3658. vmw_execbuf_unpin_panic(dev_priv);
  3659. goto out_no_emit;
  3660. }
  3661. dev_priv->query_cid_valid = false;
  3662. }
  3663. vmw_bo_pin_reserved(dev_priv->pinned_bo, false);
  3664. if (dev_priv->dummy_query_bo_pinned) {
  3665. vmw_bo_pin_reserved(dev_priv->dummy_query_bo, false);
  3666. dev_priv->dummy_query_bo_pinned = false;
  3667. }
  3668. if (fence == NULL) {
  3669. (void) vmw_execbuf_fence_commands(NULL, dev_priv, &lfence,
  3670. NULL);
  3671. fence = lfence;
  3672. }
  3673. ttm_eu_fence_buffer_objects(&ticket, &validate_list, (void *) fence);
  3674. if (lfence != NULL)
  3675. vmw_fence_obj_unreference(&lfence);
  3676. ttm_bo_unref(&query_val.bo);
  3677. ttm_bo_unref(&pinned_val.bo);
  3678. vmw_dmabuf_unreference(&dev_priv->pinned_bo);
  3679. DRM_INFO("Dummy query bo pin count: %d\n",
  3680. dev_priv->dummy_query_bo->pin_count);
  3681. out_unlock:
  3682. return;
  3683. out_no_emit:
  3684. ttm_eu_backoff_reservation(&ticket, &validate_list);
  3685. out_no_reserve:
  3686. ttm_bo_unref(&query_val.bo);
  3687. ttm_bo_unref(&pinned_val.bo);
  3688. vmw_dmabuf_unreference(&dev_priv->pinned_bo);
  3689. }
  3690. /**
  3691. * vmw_execbuf_release_pinned_bo - Flush queries and unpin the pinned
  3692. * query bo.
  3693. *
  3694. * @dev_priv: The device private structure.
  3695. *
  3696. * This function should be used to unpin the pinned query bo, or
  3697. * as a query barrier when we need to make sure that all queries have
  3698. * finished before the next fifo command. (For example on hardware
  3699. * context destructions where the hardware may otherwise leak unfinished
  3700. * queries).
  3701. *
  3702. * This function does not return any failure codes, but make attempts
  3703. * to do safe unpinning in case of errors.
  3704. *
  3705. * The function will synchronize on the previous query barrier, and will
  3706. * thus not finish until that barrier has executed.
  3707. */
  3708. void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv)
  3709. {
  3710. mutex_lock(&dev_priv->cmdbuf_mutex);
  3711. if (dev_priv->query_cid_valid)
  3712. __vmw_execbuf_release_pinned_bo(dev_priv, NULL);
  3713. mutex_unlock(&dev_priv->cmdbuf_mutex);
  3714. }
  3715. int vmw_execbuf_ioctl(struct drm_device *dev, unsigned long data,
  3716. struct drm_file *file_priv, size_t size)
  3717. {
  3718. struct vmw_private *dev_priv = vmw_priv(dev);
  3719. struct drm_vmw_execbuf_arg arg;
  3720. int ret;
  3721. static const size_t copy_offset[] = {
  3722. offsetof(struct drm_vmw_execbuf_arg, context_handle),
  3723. sizeof(struct drm_vmw_execbuf_arg)};
  3724. if (unlikely(size < copy_offset[0])) {
  3725. DRM_ERROR("Invalid command size, ioctl %d\n",
  3726. DRM_VMW_EXECBUF);
  3727. return -EINVAL;
  3728. }
  3729. if (copy_from_user(&arg, (void __user *) data, copy_offset[0]) != 0)
  3730. return -EFAULT;
  3731. /*
  3732. * Extend the ioctl argument while
  3733. * maintaining backwards compatibility:
  3734. * We take different code paths depending on the value of
  3735. * arg.version.
  3736. */
  3737. if (unlikely(arg.version > DRM_VMW_EXECBUF_VERSION ||
  3738. arg.version == 0)) {
  3739. DRM_ERROR("Incorrect execbuf version.\n");
  3740. return -EINVAL;
  3741. }
  3742. if (arg.version > 1 &&
  3743. copy_from_user(&arg.context_handle,
  3744. (void __user *) (data + copy_offset[0]),
  3745. copy_offset[arg.version - 1] -
  3746. copy_offset[0]) != 0)
  3747. return -EFAULT;
  3748. switch (arg.version) {
  3749. case 1:
  3750. arg.context_handle = (uint32_t) -1;
  3751. break;
  3752. case 2:
  3753. if (arg.pad64 != 0) {
  3754. DRM_ERROR("Unused IOCTL data not set to zero.\n");
  3755. return -EINVAL;
  3756. }
  3757. break;
  3758. default:
  3759. break;
  3760. }
  3761. ret = ttm_read_lock(&dev_priv->reservation_sem, true);
  3762. if (unlikely(ret != 0))
  3763. return ret;
  3764. ret = vmw_execbuf_process(file_priv, dev_priv,
  3765. (void __user *)(unsigned long)arg.commands,
  3766. NULL, arg.command_size, arg.throttle_us,
  3767. arg.context_handle,
  3768. (void __user *)(unsigned long)arg.fence_rep,
  3769. NULL);
  3770. ttm_read_unlock(&dev_priv->reservation_sem);
  3771. if (unlikely(ret != 0))
  3772. return ret;
  3773. vmw_kms_cursor_post_execbuf(dev_priv);
  3774. return 0;
  3775. }