vmwgfx_kms.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958
  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_kms.h"
  28. #include <drm/drm_plane_helper.h>
  29. #include <drm/drm_atomic.h>
  30. #include <drm/drm_atomic_helper.h>
  31. #include <drm/drm_rect.h>
  32. /* Might need a hrtimer here? */
  33. #define VMWGFX_PRESENT_RATE ((HZ / 60 > 0) ? HZ / 60 : 1)
  34. void vmw_du_cleanup(struct vmw_display_unit *du)
  35. {
  36. drm_plane_cleanup(&du->primary);
  37. drm_plane_cleanup(&du->cursor);
  38. drm_connector_unregister(&du->connector);
  39. drm_crtc_cleanup(&du->crtc);
  40. drm_encoder_cleanup(&du->encoder);
  41. drm_connector_cleanup(&du->connector);
  42. }
  43. /*
  44. * Display Unit Cursor functions
  45. */
  46. static int vmw_cursor_update_image(struct vmw_private *dev_priv,
  47. u32 *image, u32 width, u32 height,
  48. u32 hotspotX, u32 hotspotY)
  49. {
  50. struct {
  51. u32 cmd;
  52. SVGAFifoCmdDefineAlphaCursor cursor;
  53. } *cmd;
  54. u32 image_size = width * height * 4;
  55. u32 cmd_size = sizeof(*cmd) + image_size;
  56. if (!image)
  57. return -EINVAL;
  58. cmd = vmw_fifo_reserve(dev_priv, cmd_size);
  59. if (unlikely(cmd == NULL)) {
  60. DRM_ERROR("Fifo reserve failed.\n");
  61. return -ENOMEM;
  62. }
  63. memset(cmd, 0, sizeof(*cmd));
  64. memcpy(&cmd[1], image, image_size);
  65. cmd->cmd = SVGA_CMD_DEFINE_ALPHA_CURSOR;
  66. cmd->cursor.id = 0;
  67. cmd->cursor.width = width;
  68. cmd->cursor.height = height;
  69. cmd->cursor.hotspotX = hotspotX;
  70. cmd->cursor.hotspotY = hotspotY;
  71. vmw_fifo_commit_flush(dev_priv, cmd_size);
  72. return 0;
  73. }
  74. static int vmw_cursor_update_dmabuf(struct vmw_private *dev_priv,
  75. struct vmw_dma_buffer *dmabuf,
  76. u32 width, u32 height,
  77. u32 hotspotX, u32 hotspotY)
  78. {
  79. struct ttm_bo_kmap_obj map;
  80. unsigned long kmap_offset;
  81. unsigned long kmap_num;
  82. void *virtual;
  83. bool dummy;
  84. int ret;
  85. kmap_offset = 0;
  86. kmap_num = (width*height*4 + PAGE_SIZE - 1) >> PAGE_SHIFT;
  87. ret = ttm_bo_reserve(&dmabuf->base, true, false, NULL);
  88. if (unlikely(ret != 0)) {
  89. DRM_ERROR("reserve failed\n");
  90. return -EINVAL;
  91. }
  92. ret = ttm_bo_kmap(&dmabuf->base, kmap_offset, kmap_num, &map);
  93. if (unlikely(ret != 0))
  94. goto err_unreserve;
  95. virtual = ttm_kmap_obj_virtual(&map, &dummy);
  96. ret = vmw_cursor_update_image(dev_priv, virtual, width, height,
  97. hotspotX, hotspotY);
  98. ttm_bo_kunmap(&map);
  99. err_unreserve:
  100. ttm_bo_unreserve(&dmabuf->base);
  101. return ret;
  102. }
  103. static void vmw_cursor_update_position(struct vmw_private *dev_priv,
  104. bool show, int x, int y)
  105. {
  106. u32 *fifo_mem = dev_priv->mmio_virt;
  107. uint32_t count;
  108. spin_lock(&dev_priv->cursor_lock);
  109. vmw_mmio_write(show ? 1 : 0, fifo_mem + SVGA_FIFO_CURSOR_ON);
  110. vmw_mmio_write(x, fifo_mem + SVGA_FIFO_CURSOR_X);
  111. vmw_mmio_write(y, fifo_mem + SVGA_FIFO_CURSOR_Y);
  112. count = vmw_mmio_read(fifo_mem + SVGA_FIFO_CURSOR_COUNT);
  113. vmw_mmio_write(++count, fifo_mem + SVGA_FIFO_CURSOR_COUNT);
  114. spin_unlock(&dev_priv->cursor_lock);
  115. }
  116. void vmw_kms_cursor_snoop(struct vmw_surface *srf,
  117. struct ttm_object_file *tfile,
  118. struct ttm_buffer_object *bo,
  119. SVGA3dCmdHeader *header)
  120. {
  121. struct ttm_bo_kmap_obj map;
  122. unsigned long kmap_offset;
  123. unsigned long kmap_num;
  124. SVGA3dCopyBox *box;
  125. unsigned box_count;
  126. void *virtual;
  127. bool dummy;
  128. struct vmw_dma_cmd {
  129. SVGA3dCmdHeader header;
  130. SVGA3dCmdSurfaceDMA dma;
  131. } *cmd;
  132. int i, ret;
  133. cmd = container_of(header, struct vmw_dma_cmd, header);
  134. /* No snooper installed */
  135. if (!srf->snooper.image)
  136. return;
  137. if (cmd->dma.host.face != 0 || cmd->dma.host.mipmap != 0) {
  138. DRM_ERROR("face and mipmap for cursors should never != 0\n");
  139. return;
  140. }
  141. if (cmd->header.size < 64) {
  142. DRM_ERROR("at least one full copy box must be given\n");
  143. return;
  144. }
  145. box = (SVGA3dCopyBox *)&cmd[1];
  146. box_count = (cmd->header.size - sizeof(SVGA3dCmdSurfaceDMA)) /
  147. sizeof(SVGA3dCopyBox);
  148. if (cmd->dma.guest.ptr.offset % PAGE_SIZE ||
  149. box->x != 0 || box->y != 0 || box->z != 0 ||
  150. box->srcx != 0 || box->srcy != 0 || box->srcz != 0 ||
  151. box->d != 1 || box_count != 1) {
  152. /* TODO handle none page aligned offsets */
  153. /* TODO handle more dst & src != 0 */
  154. /* TODO handle more then one copy */
  155. DRM_ERROR("Cant snoop dma request for cursor!\n");
  156. DRM_ERROR("(%u, %u, %u) (%u, %u, %u) (%ux%ux%u) %u %u\n",
  157. box->srcx, box->srcy, box->srcz,
  158. box->x, box->y, box->z,
  159. box->w, box->h, box->d, box_count,
  160. cmd->dma.guest.ptr.offset);
  161. return;
  162. }
  163. kmap_offset = cmd->dma.guest.ptr.offset >> PAGE_SHIFT;
  164. kmap_num = (64*64*4) >> PAGE_SHIFT;
  165. ret = ttm_bo_reserve(bo, true, false, NULL);
  166. if (unlikely(ret != 0)) {
  167. DRM_ERROR("reserve failed\n");
  168. return;
  169. }
  170. ret = ttm_bo_kmap(bo, kmap_offset, kmap_num, &map);
  171. if (unlikely(ret != 0))
  172. goto err_unreserve;
  173. virtual = ttm_kmap_obj_virtual(&map, &dummy);
  174. if (box->w == 64 && cmd->dma.guest.pitch == 64*4) {
  175. memcpy(srf->snooper.image, virtual, 64*64*4);
  176. } else {
  177. /* Image is unsigned pointer. */
  178. for (i = 0; i < box->h; i++)
  179. memcpy(srf->snooper.image + i * 64,
  180. virtual + i * cmd->dma.guest.pitch,
  181. box->w * 4);
  182. }
  183. srf->snooper.age++;
  184. ttm_bo_kunmap(&map);
  185. err_unreserve:
  186. ttm_bo_unreserve(bo);
  187. }
  188. /**
  189. * vmw_kms_legacy_hotspot_clear - Clear legacy hotspots
  190. *
  191. * @dev_priv: Pointer to the device private struct.
  192. *
  193. * Clears all legacy hotspots.
  194. */
  195. void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv)
  196. {
  197. struct drm_device *dev = dev_priv->dev;
  198. struct vmw_display_unit *du;
  199. struct drm_crtc *crtc;
  200. drm_modeset_lock_all(dev);
  201. drm_for_each_crtc(crtc, dev) {
  202. du = vmw_crtc_to_du(crtc);
  203. du->hotspot_x = 0;
  204. du->hotspot_y = 0;
  205. }
  206. drm_modeset_unlock_all(dev);
  207. }
  208. void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv)
  209. {
  210. struct drm_device *dev = dev_priv->dev;
  211. struct vmw_display_unit *du;
  212. struct drm_crtc *crtc;
  213. mutex_lock(&dev->mode_config.mutex);
  214. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  215. du = vmw_crtc_to_du(crtc);
  216. if (!du->cursor_surface ||
  217. du->cursor_age == du->cursor_surface->snooper.age)
  218. continue;
  219. du->cursor_age = du->cursor_surface->snooper.age;
  220. vmw_cursor_update_image(dev_priv,
  221. du->cursor_surface->snooper.image,
  222. 64, 64,
  223. du->hotspot_x + du->core_hotspot_x,
  224. du->hotspot_y + du->core_hotspot_y);
  225. }
  226. mutex_unlock(&dev->mode_config.mutex);
  227. }
  228. /**
  229. * vmw_du_cursor_plane_update() - Update cursor image and location
  230. *
  231. * @plane: plane object to update
  232. * @crtc: owning CRTC of @plane
  233. * @fb: framebuffer to flip onto plane
  234. * @crtc_x: x offset of plane on crtc
  235. * @crtc_y: y offset of plane on crtc
  236. * @crtc_w: width of plane rectangle on crtc
  237. * @crtc_h: height of plane rectangle on crtc
  238. * @src_x: Not used
  239. * @src_y: Not used
  240. * @src_w: Not used
  241. * @src_h: Not used
  242. *
  243. *
  244. * RETURNS:
  245. * Zero on success, error code on failure
  246. */
  247. int vmw_du_cursor_plane_update(struct drm_plane *plane,
  248. struct drm_crtc *crtc,
  249. struct drm_framebuffer *fb,
  250. int crtc_x, int crtc_y,
  251. unsigned int crtc_w,
  252. unsigned int crtc_h,
  253. uint32_t src_x, uint32_t src_y,
  254. uint32_t src_w, uint32_t src_h)
  255. {
  256. struct vmw_private *dev_priv = vmw_priv(crtc->dev);
  257. struct vmw_display_unit *du = vmw_crtc_to_du(crtc);
  258. struct vmw_surface *surface = NULL;
  259. struct vmw_dma_buffer *dmabuf = NULL;
  260. s32 hotspot_x, hotspot_y;
  261. int ret;
  262. hotspot_x = du->hotspot_x + fb->hot_x;
  263. hotspot_y = du->hotspot_y + fb->hot_y;
  264. /* A lot of the code assumes this */
  265. if (crtc_w != 64 || crtc_h != 64) {
  266. ret = -EINVAL;
  267. goto out;
  268. }
  269. if (vmw_framebuffer_to_vfb(fb)->dmabuf)
  270. dmabuf = vmw_framebuffer_to_vfbd(fb)->buffer;
  271. else
  272. surface = vmw_framebuffer_to_vfbs(fb)->surface;
  273. if (surface && !surface->snooper.image) {
  274. DRM_ERROR("surface not suitable for cursor\n");
  275. ret = -EINVAL;
  276. goto out;
  277. }
  278. /* setup new image */
  279. ret = 0;
  280. if (surface) {
  281. /* vmw_user_surface_lookup takes one reference */
  282. du->cursor_surface = surface;
  283. du->cursor_age = du->cursor_surface->snooper.age;
  284. ret = vmw_cursor_update_image(dev_priv, surface->snooper.image,
  285. 64, 64, hotspot_x, hotspot_y);
  286. } else if (dmabuf) {
  287. /* vmw_user_surface_lookup takes one reference */
  288. du->cursor_dmabuf = dmabuf;
  289. ret = vmw_cursor_update_dmabuf(dev_priv, dmabuf, crtc_w, crtc_h,
  290. hotspot_x, hotspot_y);
  291. } else {
  292. vmw_cursor_update_position(dev_priv, false, 0, 0);
  293. goto out;
  294. }
  295. if (!ret) {
  296. du->cursor_x = crtc_x + du->set_gui_x;
  297. du->cursor_y = crtc_y + du->set_gui_y;
  298. vmw_cursor_update_position(dev_priv, true,
  299. du->cursor_x + hotspot_x,
  300. du->cursor_y + hotspot_y);
  301. }
  302. out:
  303. return ret;
  304. }
  305. int vmw_du_cursor_plane_disable(struct drm_plane *plane)
  306. {
  307. if (plane->fb) {
  308. drm_framebuffer_unreference(plane->fb);
  309. plane->fb = NULL;
  310. }
  311. return -EINVAL;
  312. }
  313. void vmw_du_cursor_plane_destroy(struct drm_plane *plane)
  314. {
  315. vmw_cursor_update_position(plane->dev->dev_private, false, 0, 0);
  316. drm_plane_cleanup(plane);
  317. }
  318. void vmw_du_primary_plane_destroy(struct drm_plane *plane)
  319. {
  320. drm_plane_cleanup(plane);
  321. /* Planes are static in our case so we don't free it */
  322. }
  323. /**
  324. * vmw_du_vps_unpin_surf - unpins resource associated with a framebuffer surface
  325. *
  326. * @vps: plane state associated with the display surface
  327. * @unreference: true if we also want to unreference the display.
  328. */
  329. void vmw_du_plane_unpin_surf(struct vmw_plane_state *vps,
  330. bool unreference)
  331. {
  332. if (vps->surf) {
  333. if (vps->pinned) {
  334. vmw_resource_unpin(&vps->surf->res);
  335. vps->pinned--;
  336. }
  337. if (unreference) {
  338. if (vps->pinned)
  339. DRM_ERROR("Surface still pinned\n");
  340. vmw_surface_unreference(&vps->surf);
  341. }
  342. }
  343. }
  344. /**
  345. * vmw_du_plane_cleanup_fb - Unpins the cursor
  346. *
  347. * @plane: display plane
  348. * @old_state: Contains the FB to clean up
  349. *
  350. * Unpins the framebuffer surface
  351. *
  352. * Returns 0 on success
  353. */
  354. void
  355. vmw_du_plane_cleanup_fb(struct drm_plane *plane,
  356. struct drm_plane_state *old_state)
  357. {
  358. struct vmw_plane_state *vps = vmw_plane_state_to_vps(old_state);
  359. vmw_du_plane_unpin_surf(vps, false);
  360. }
  361. /**
  362. * vmw_du_cursor_plane_prepare_fb - Readies the cursor by referencing it
  363. *
  364. * @plane: display plane
  365. * @new_state: info on the new plane state, including the FB
  366. *
  367. * Returns 0 on success
  368. */
  369. int
  370. vmw_du_cursor_plane_prepare_fb(struct drm_plane *plane,
  371. struct drm_plane_state *new_state)
  372. {
  373. struct drm_framebuffer *fb = new_state->fb;
  374. struct vmw_plane_state *vps = vmw_plane_state_to_vps(new_state);
  375. if (vps->surf)
  376. vmw_surface_unreference(&vps->surf);
  377. if (vps->dmabuf)
  378. vmw_dmabuf_unreference(&vps->dmabuf);
  379. if (fb) {
  380. if (vmw_framebuffer_to_vfb(fb)->dmabuf) {
  381. vps->dmabuf = vmw_framebuffer_to_vfbd(fb)->buffer;
  382. vmw_dmabuf_reference(vps->dmabuf);
  383. } else {
  384. vps->surf = vmw_framebuffer_to_vfbs(fb)->surface;
  385. vmw_surface_reference(vps->surf);
  386. }
  387. }
  388. return 0;
  389. }
  390. void
  391. vmw_du_cursor_plane_atomic_disable(struct drm_plane *plane,
  392. struct drm_plane_state *old_state)
  393. {
  394. struct drm_crtc *crtc = plane->state->crtc ?: old_state->crtc;
  395. struct vmw_private *dev_priv = vmw_priv(crtc->dev);
  396. drm_atomic_set_fb_for_plane(plane->state, NULL);
  397. vmw_cursor_update_position(dev_priv, false, 0, 0);
  398. }
  399. void
  400. vmw_du_cursor_plane_atomic_update(struct drm_plane *plane,
  401. struct drm_plane_state *old_state)
  402. {
  403. struct drm_crtc *crtc = plane->state->crtc ?: old_state->crtc;
  404. struct vmw_private *dev_priv = vmw_priv(crtc->dev);
  405. struct vmw_display_unit *du = vmw_crtc_to_du(crtc);
  406. struct vmw_plane_state *vps = vmw_plane_state_to_vps(plane->state);
  407. s32 hotspot_x, hotspot_y;
  408. int ret = 0;
  409. hotspot_x = du->hotspot_x;
  410. hotspot_y = du->hotspot_y;
  411. du->cursor_surface = vps->surf;
  412. du->cursor_dmabuf = vps->dmabuf;
  413. /* setup new image */
  414. if (vps->surf) {
  415. du->cursor_age = du->cursor_surface->snooper.age;
  416. ret = vmw_cursor_update_image(dev_priv,
  417. vps->surf->snooper.image,
  418. 64, 64, hotspot_x, hotspot_y);
  419. } else if (vps->dmabuf) {
  420. ret = vmw_cursor_update_dmabuf(dev_priv, vps->dmabuf,
  421. plane->state->crtc_w,
  422. plane->state->crtc_h,
  423. hotspot_x, hotspot_y);
  424. } else {
  425. vmw_cursor_update_position(dev_priv, false, 0, 0);
  426. return;
  427. }
  428. if (!ret) {
  429. du->cursor_x = plane->state->crtc_x + du->set_gui_x;
  430. du->cursor_y = plane->state->crtc_y + du->set_gui_y;
  431. vmw_cursor_update_position(dev_priv, true,
  432. du->cursor_x + hotspot_x,
  433. du->cursor_y + hotspot_y);
  434. } else {
  435. DRM_ERROR("Failed to update cursor image\n");
  436. }
  437. }
  438. /**
  439. * vmw_du_primary_plane_atomic_check - check if the new state is okay
  440. *
  441. * @plane: display plane
  442. * @state: info on the new plane state, including the FB
  443. *
  444. * Check if the new state is settable given the current state. Other
  445. * than what the atomic helper checks, we care about crtc fitting
  446. * the FB and maintaining one active framebuffer.
  447. *
  448. * Returns 0 on success
  449. */
  450. int vmw_du_primary_plane_atomic_check(struct drm_plane *plane,
  451. struct drm_plane_state *state)
  452. {
  453. struct drm_framebuffer *new_fb = state->fb;
  454. bool visible;
  455. struct drm_rect src = {
  456. .x1 = state->src_x,
  457. .y1 = state->src_y,
  458. .x2 = state->src_x + state->src_w,
  459. .y2 = state->src_y + state->src_h,
  460. };
  461. struct drm_rect dest = {
  462. .x1 = state->crtc_x,
  463. .y1 = state->crtc_y,
  464. .x2 = state->crtc_x + state->crtc_w,
  465. .y2 = state->crtc_y + state->crtc_h,
  466. };
  467. struct drm_rect clip = dest;
  468. int ret;
  469. ret = drm_plane_helper_check_update(plane, state->crtc, new_fb,
  470. &src, &dest, &clip,
  471. DRM_ROTATE_0,
  472. DRM_PLANE_HELPER_NO_SCALING,
  473. DRM_PLANE_HELPER_NO_SCALING,
  474. false, true, &visible);
  475. if (!ret && new_fb) {
  476. struct drm_crtc *crtc = state->crtc;
  477. struct vmw_connector_state *vcs;
  478. struct vmw_display_unit *du = vmw_crtc_to_du(crtc);
  479. struct vmw_private *dev_priv = vmw_priv(crtc->dev);
  480. struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(new_fb);
  481. vcs = vmw_connector_state_to_vcs(du->connector.state);
  482. if ((dest.x2 > new_fb->width ||
  483. dest.y2 > new_fb->height)) {
  484. DRM_ERROR("CRTC area outside of framebuffer\n");
  485. return -EINVAL;
  486. }
  487. /* Only one active implicit framebuffer at a time. */
  488. mutex_lock(&dev_priv->global_kms_state_mutex);
  489. if (vcs->is_implicit && dev_priv->implicit_fb &&
  490. !(dev_priv->num_implicit == 1 && du->active_implicit)
  491. && dev_priv->implicit_fb != vfb) {
  492. DRM_ERROR("Multiple implicit framebuffers "
  493. "not supported.\n");
  494. ret = -EINVAL;
  495. }
  496. mutex_unlock(&dev_priv->global_kms_state_mutex);
  497. }
  498. return ret;
  499. }
  500. /**
  501. * vmw_du_cursor_plane_atomic_check - check if the new state is okay
  502. *
  503. * @plane: cursor plane
  504. * @state: info on the new plane state
  505. *
  506. * This is a chance to fail if the new cursor state does not fit
  507. * our requirements.
  508. *
  509. * Returns 0 on success
  510. */
  511. int vmw_du_cursor_plane_atomic_check(struct drm_plane *plane,
  512. struct drm_plane_state *new_state)
  513. {
  514. int ret = 0;
  515. struct vmw_surface *surface = NULL;
  516. struct drm_framebuffer *fb = new_state->fb;
  517. /* Turning off */
  518. if (!fb)
  519. return ret;
  520. /* A lot of the code assumes this */
  521. if (new_state->crtc_w != 64 || new_state->crtc_h != 64) {
  522. DRM_ERROR("Invalid cursor dimensions (%d, %d)\n",
  523. new_state->crtc_w, new_state->crtc_h);
  524. ret = -EINVAL;
  525. }
  526. if (!vmw_framebuffer_to_vfb(fb)->dmabuf)
  527. surface = vmw_framebuffer_to_vfbs(fb)->surface;
  528. if (surface && !surface->snooper.image) {
  529. DRM_ERROR("surface not suitable for cursor\n");
  530. ret = -EINVAL;
  531. }
  532. return ret;
  533. }
  534. int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
  535. struct drm_crtc_state *new_state)
  536. {
  537. struct vmw_display_unit *du = vmw_crtc_to_du(new_state->crtc);
  538. int connector_mask = 1 << drm_connector_index(&du->connector);
  539. bool has_primary = new_state->plane_mask &
  540. BIT(drm_plane_index(crtc->primary));
  541. /* We always want to have an active plane with an active CRTC */
  542. if (has_primary != new_state->enable)
  543. return -EINVAL;
  544. if (new_state->connector_mask != connector_mask &&
  545. new_state->connector_mask != 0) {
  546. DRM_ERROR("Invalid connectors configuration\n");
  547. return -EINVAL;
  548. }
  549. /*
  550. * Our virtual device does not have a dot clock, so use the logical
  551. * clock value as the dot clock.
  552. */
  553. if (new_state->mode.crtc_clock == 0)
  554. new_state->adjusted_mode.crtc_clock = new_state->mode.clock;
  555. return 0;
  556. }
  557. void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
  558. struct drm_crtc_state *old_crtc_state)
  559. {
  560. }
  561. void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
  562. struct drm_crtc_state *old_crtc_state)
  563. {
  564. struct drm_pending_vblank_event *event = crtc->state->event;
  565. if (event) {
  566. crtc->state->event = NULL;
  567. spin_lock_irq(&crtc->dev->event_lock);
  568. if (drm_crtc_vblank_get(crtc) == 0)
  569. drm_crtc_arm_vblank_event(crtc, event);
  570. else
  571. drm_crtc_send_vblank_event(crtc, event);
  572. spin_unlock_irq(&crtc->dev->event_lock);
  573. }
  574. }
  575. /**
  576. * vmw_du_crtc_duplicate_state - duplicate crtc state
  577. * @crtc: DRM crtc
  578. *
  579. * Allocates and returns a copy of the crtc state (both common and
  580. * vmw-specific) for the specified crtc.
  581. *
  582. * Returns: The newly allocated crtc state, or NULL on failure.
  583. */
  584. struct drm_crtc_state *
  585. vmw_du_crtc_duplicate_state(struct drm_crtc *crtc)
  586. {
  587. struct drm_crtc_state *state;
  588. struct vmw_crtc_state *vcs;
  589. if (WARN_ON(!crtc->state))
  590. return NULL;
  591. vcs = kmemdup(crtc->state, sizeof(*vcs), GFP_KERNEL);
  592. if (!vcs)
  593. return NULL;
  594. state = &vcs->base;
  595. __drm_atomic_helper_crtc_duplicate_state(crtc, state);
  596. return state;
  597. }
  598. /**
  599. * vmw_du_crtc_reset - creates a blank vmw crtc state
  600. * @crtc: DRM crtc
  601. *
  602. * Resets the atomic state for @crtc by freeing the state pointer (which
  603. * might be NULL, e.g. at driver load time) and allocating a new empty state
  604. * object.
  605. */
  606. void vmw_du_crtc_reset(struct drm_crtc *crtc)
  607. {
  608. struct vmw_crtc_state *vcs;
  609. if (crtc->state) {
  610. __drm_atomic_helper_crtc_destroy_state(crtc->state);
  611. kfree(vmw_crtc_state_to_vcs(crtc->state));
  612. }
  613. vcs = kzalloc(sizeof(*vcs), GFP_KERNEL);
  614. if (!vcs) {
  615. DRM_ERROR("Cannot allocate vmw_crtc_state\n");
  616. return;
  617. }
  618. crtc->state = &vcs->base;
  619. crtc->state->crtc = crtc;
  620. }
  621. /**
  622. * vmw_du_crtc_destroy_state - destroy crtc state
  623. * @crtc: DRM crtc
  624. * @state: state object to destroy
  625. *
  626. * Destroys the crtc state (both common and vmw-specific) for the
  627. * specified plane.
  628. */
  629. void
  630. vmw_du_crtc_destroy_state(struct drm_crtc *crtc,
  631. struct drm_crtc_state *state)
  632. {
  633. drm_atomic_helper_crtc_destroy_state(crtc, state);
  634. }
  635. /**
  636. * vmw_du_plane_duplicate_state - duplicate plane state
  637. * @plane: drm plane
  638. *
  639. * Allocates and returns a copy of the plane state (both common and
  640. * vmw-specific) for the specified plane.
  641. *
  642. * Returns: The newly allocated plane state, or NULL on failure.
  643. */
  644. struct drm_plane_state *
  645. vmw_du_plane_duplicate_state(struct drm_plane *plane)
  646. {
  647. struct drm_plane_state *state;
  648. struct vmw_plane_state *vps;
  649. vps = kmemdup(plane->state, sizeof(*vps), GFP_KERNEL);
  650. if (!vps)
  651. return NULL;
  652. vps->pinned = 0;
  653. /* Mapping is managed by prepare_fb/cleanup_fb */
  654. memset(&vps->guest_map, 0, sizeof(vps->guest_map));
  655. memset(&vps->host_map, 0, sizeof(vps->host_map));
  656. vps->cpp = 0;
  657. /* Each ref counted resource needs to be acquired again */
  658. if (vps->surf)
  659. (void) vmw_surface_reference(vps->surf);
  660. if (vps->dmabuf)
  661. (void) vmw_dmabuf_reference(vps->dmabuf);
  662. state = &vps->base;
  663. __drm_atomic_helper_plane_duplicate_state(plane, state);
  664. return state;
  665. }
  666. /**
  667. * vmw_du_plane_reset - creates a blank vmw plane state
  668. * @plane: drm plane
  669. *
  670. * Resets the atomic state for @plane by freeing the state pointer (which might
  671. * be NULL, e.g. at driver load time) and allocating a new empty state object.
  672. */
  673. void vmw_du_plane_reset(struct drm_plane *plane)
  674. {
  675. struct vmw_plane_state *vps;
  676. if (plane->state)
  677. vmw_du_plane_destroy_state(plane, plane->state);
  678. vps = kzalloc(sizeof(*vps), GFP_KERNEL);
  679. if (!vps) {
  680. DRM_ERROR("Cannot allocate vmw_plane_state\n");
  681. return;
  682. }
  683. plane->state = &vps->base;
  684. plane->state->plane = plane;
  685. plane->state->rotation = DRM_ROTATE_0;
  686. }
  687. /**
  688. * vmw_du_plane_destroy_state - destroy plane state
  689. * @plane: DRM plane
  690. * @state: state object to destroy
  691. *
  692. * Destroys the plane state (both common and vmw-specific) for the
  693. * specified plane.
  694. */
  695. void
  696. vmw_du_plane_destroy_state(struct drm_plane *plane,
  697. struct drm_plane_state *state)
  698. {
  699. struct vmw_plane_state *vps = vmw_plane_state_to_vps(state);
  700. /* Should have been freed by cleanup_fb */
  701. if (vps->guest_map.virtual) {
  702. DRM_ERROR("Guest mapping not freed\n");
  703. ttm_bo_kunmap(&vps->guest_map);
  704. }
  705. if (vps->host_map.virtual) {
  706. DRM_ERROR("Host mapping not freed\n");
  707. ttm_bo_kunmap(&vps->host_map);
  708. }
  709. if (vps->surf)
  710. vmw_surface_unreference(&vps->surf);
  711. if (vps->dmabuf)
  712. vmw_dmabuf_unreference(&vps->dmabuf);
  713. drm_atomic_helper_plane_destroy_state(plane, state);
  714. }
  715. /**
  716. * vmw_du_connector_duplicate_state - duplicate connector state
  717. * @connector: DRM connector
  718. *
  719. * Allocates and returns a copy of the connector state (both common and
  720. * vmw-specific) for the specified connector.
  721. *
  722. * Returns: The newly allocated connector state, or NULL on failure.
  723. */
  724. struct drm_connector_state *
  725. vmw_du_connector_duplicate_state(struct drm_connector *connector)
  726. {
  727. struct drm_connector_state *state;
  728. struct vmw_connector_state *vcs;
  729. if (WARN_ON(!connector->state))
  730. return NULL;
  731. vcs = kmemdup(connector->state, sizeof(*vcs), GFP_KERNEL);
  732. if (!vcs)
  733. return NULL;
  734. state = &vcs->base;
  735. __drm_atomic_helper_connector_duplicate_state(connector, state);
  736. return state;
  737. }
  738. /**
  739. * vmw_du_connector_reset - creates a blank vmw connector state
  740. * @connector: DRM connector
  741. *
  742. * Resets the atomic state for @connector by freeing the state pointer (which
  743. * might be NULL, e.g. at driver load time) and allocating a new empty state
  744. * object.
  745. */
  746. void vmw_du_connector_reset(struct drm_connector *connector)
  747. {
  748. struct vmw_connector_state *vcs;
  749. if (connector->state) {
  750. __drm_atomic_helper_connector_destroy_state(connector->state);
  751. kfree(vmw_connector_state_to_vcs(connector->state));
  752. }
  753. vcs = kzalloc(sizeof(*vcs), GFP_KERNEL);
  754. if (!vcs) {
  755. DRM_ERROR("Cannot allocate vmw_connector_state\n");
  756. return;
  757. }
  758. __drm_atomic_helper_connector_reset(connector, &vcs->base);
  759. }
  760. /**
  761. * vmw_du_connector_destroy_state - destroy connector state
  762. * @connector: DRM connector
  763. * @state: state object to destroy
  764. *
  765. * Destroys the connector state (both common and vmw-specific) for the
  766. * specified plane.
  767. */
  768. void
  769. vmw_du_connector_destroy_state(struct drm_connector *connector,
  770. struct drm_connector_state *state)
  771. {
  772. drm_atomic_helper_connector_destroy_state(connector, state);
  773. }
  774. /*
  775. * Generic framebuffer code
  776. */
  777. /*
  778. * Surface framebuffer code
  779. */
  780. static void vmw_framebuffer_surface_destroy(struct drm_framebuffer *framebuffer)
  781. {
  782. struct vmw_framebuffer_surface *vfbs =
  783. vmw_framebuffer_to_vfbs(framebuffer);
  784. drm_framebuffer_cleanup(framebuffer);
  785. vmw_surface_unreference(&vfbs->surface);
  786. if (vfbs->base.user_obj)
  787. ttm_base_object_unref(&vfbs->base.user_obj);
  788. kfree(vfbs);
  789. }
  790. static int vmw_framebuffer_surface_dirty(struct drm_framebuffer *framebuffer,
  791. struct drm_file *file_priv,
  792. unsigned flags, unsigned color,
  793. struct drm_clip_rect *clips,
  794. unsigned num_clips)
  795. {
  796. struct vmw_private *dev_priv = vmw_priv(framebuffer->dev);
  797. struct vmw_framebuffer_surface *vfbs =
  798. vmw_framebuffer_to_vfbs(framebuffer);
  799. struct drm_clip_rect norect;
  800. int ret, inc = 1;
  801. /* Legacy Display Unit does not support 3D */
  802. if (dev_priv->active_display_unit == vmw_du_legacy)
  803. return -EINVAL;
  804. drm_modeset_lock_all(dev_priv->dev);
  805. ret = ttm_read_lock(&dev_priv->reservation_sem, true);
  806. if (unlikely(ret != 0)) {
  807. drm_modeset_unlock_all(dev_priv->dev);
  808. return ret;
  809. }
  810. if (!num_clips) {
  811. num_clips = 1;
  812. clips = &norect;
  813. norect.x1 = norect.y1 = 0;
  814. norect.x2 = framebuffer->width;
  815. norect.y2 = framebuffer->height;
  816. } else if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY) {
  817. num_clips /= 2;
  818. inc = 2; /* skip source rects */
  819. }
  820. if (dev_priv->active_display_unit == vmw_du_screen_object)
  821. ret = vmw_kms_sou_do_surface_dirty(dev_priv, &vfbs->base,
  822. clips, NULL, NULL, 0, 0,
  823. num_clips, inc, NULL);
  824. else
  825. ret = vmw_kms_stdu_surface_dirty(dev_priv, &vfbs->base,
  826. clips, NULL, NULL, 0, 0,
  827. num_clips, inc, NULL);
  828. vmw_fifo_flush(dev_priv, false);
  829. ttm_read_unlock(&dev_priv->reservation_sem);
  830. drm_modeset_unlock_all(dev_priv->dev);
  831. return 0;
  832. }
  833. /**
  834. * vmw_kms_readback - Perform a readback from the screen system to
  835. * a dma-buffer backed framebuffer.
  836. *
  837. * @dev_priv: Pointer to the device private structure.
  838. * @file_priv: Pointer to a struct drm_file identifying the caller.
  839. * Must be set to NULL if @user_fence_rep is NULL.
  840. * @vfb: Pointer to the dma-buffer backed framebuffer.
  841. * @user_fence_rep: User-space provided structure for fence information.
  842. * Must be set to non-NULL if @file_priv is non-NULL.
  843. * @vclips: Array of clip rects.
  844. * @num_clips: Number of clip rects in @vclips.
  845. *
  846. * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
  847. * interrupted.
  848. */
  849. int vmw_kms_readback(struct vmw_private *dev_priv,
  850. struct drm_file *file_priv,
  851. struct vmw_framebuffer *vfb,
  852. struct drm_vmw_fence_rep __user *user_fence_rep,
  853. struct drm_vmw_rect *vclips,
  854. uint32_t num_clips)
  855. {
  856. switch (dev_priv->active_display_unit) {
  857. case vmw_du_screen_object:
  858. return vmw_kms_sou_readback(dev_priv, file_priv, vfb,
  859. user_fence_rep, vclips, num_clips);
  860. case vmw_du_screen_target:
  861. return vmw_kms_stdu_dma(dev_priv, file_priv, vfb,
  862. user_fence_rep, NULL, vclips, num_clips,
  863. 1, false, true);
  864. default:
  865. WARN_ONCE(true,
  866. "Readback called with invalid display system.\n");
  867. }
  868. return -ENOSYS;
  869. }
  870. static const struct drm_framebuffer_funcs vmw_framebuffer_surface_funcs = {
  871. .destroy = vmw_framebuffer_surface_destroy,
  872. .dirty = vmw_framebuffer_surface_dirty,
  873. };
  874. static int vmw_kms_new_framebuffer_surface(struct vmw_private *dev_priv,
  875. struct vmw_surface *surface,
  876. struct vmw_framebuffer **out,
  877. const struct drm_mode_fb_cmd2
  878. *mode_cmd,
  879. bool is_dmabuf_proxy)
  880. {
  881. struct drm_device *dev = dev_priv->dev;
  882. struct vmw_framebuffer_surface *vfbs;
  883. enum SVGA3dSurfaceFormat format;
  884. int ret;
  885. struct drm_format_name_buf format_name;
  886. /* 3D is only supported on HWv8 and newer hosts */
  887. if (dev_priv->active_display_unit == vmw_du_legacy)
  888. return -ENOSYS;
  889. /*
  890. * Sanity checks.
  891. */
  892. /* Surface must be marked as a scanout. */
  893. if (unlikely(!surface->scanout))
  894. return -EINVAL;
  895. if (unlikely(surface->mip_levels[0] != 1 ||
  896. surface->num_sizes != 1 ||
  897. surface->base_size.width < mode_cmd->width ||
  898. surface->base_size.height < mode_cmd->height ||
  899. surface->base_size.depth != 1)) {
  900. DRM_ERROR("Incompatible surface dimensions "
  901. "for requested mode.\n");
  902. return -EINVAL;
  903. }
  904. switch (mode_cmd->pixel_format) {
  905. case DRM_FORMAT_ARGB8888:
  906. format = SVGA3D_A8R8G8B8;
  907. break;
  908. case DRM_FORMAT_XRGB8888:
  909. format = SVGA3D_X8R8G8B8;
  910. break;
  911. case DRM_FORMAT_RGB565:
  912. format = SVGA3D_R5G6B5;
  913. break;
  914. case DRM_FORMAT_XRGB1555:
  915. format = SVGA3D_A1R5G5B5;
  916. break;
  917. default:
  918. DRM_ERROR("Invalid pixel format: %s\n",
  919. drm_get_format_name(mode_cmd->pixel_format, &format_name));
  920. return -EINVAL;
  921. }
  922. /*
  923. * For DX, surface format validation is done when surface->scanout
  924. * is set.
  925. */
  926. if (!dev_priv->has_dx && format != surface->format) {
  927. DRM_ERROR("Invalid surface format for requested mode.\n");
  928. return -EINVAL;
  929. }
  930. vfbs = kzalloc(sizeof(*vfbs), GFP_KERNEL);
  931. if (!vfbs) {
  932. ret = -ENOMEM;
  933. goto out_err1;
  934. }
  935. drm_helper_mode_fill_fb_struct(dev, &vfbs->base.base, mode_cmd);
  936. vfbs->surface = vmw_surface_reference(surface);
  937. vfbs->base.user_handle = mode_cmd->handles[0];
  938. vfbs->is_dmabuf_proxy = is_dmabuf_proxy;
  939. *out = &vfbs->base;
  940. ret = drm_framebuffer_init(dev, &vfbs->base.base,
  941. &vmw_framebuffer_surface_funcs);
  942. if (ret)
  943. goto out_err2;
  944. return 0;
  945. out_err2:
  946. vmw_surface_unreference(&surface);
  947. kfree(vfbs);
  948. out_err1:
  949. return ret;
  950. }
  951. /*
  952. * Dmabuf framebuffer code
  953. */
  954. static void vmw_framebuffer_dmabuf_destroy(struct drm_framebuffer *framebuffer)
  955. {
  956. struct vmw_framebuffer_dmabuf *vfbd =
  957. vmw_framebuffer_to_vfbd(framebuffer);
  958. drm_framebuffer_cleanup(framebuffer);
  959. vmw_dmabuf_unreference(&vfbd->buffer);
  960. if (vfbd->base.user_obj)
  961. ttm_base_object_unref(&vfbd->base.user_obj);
  962. kfree(vfbd);
  963. }
  964. static int vmw_framebuffer_dmabuf_dirty(struct drm_framebuffer *framebuffer,
  965. struct drm_file *file_priv,
  966. unsigned flags, unsigned color,
  967. struct drm_clip_rect *clips,
  968. unsigned num_clips)
  969. {
  970. struct vmw_private *dev_priv = vmw_priv(framebuffer->dev);
  971. struct vmw_framebuffer_dmabuf *vfbd =
  972. vmw_framebuffer_to_vfbd(framebuffer);
  973. struct drm_clip_rect norect;
  974. int ret, increment = 1;
  975. drm_modeset_lock_all(dev_priv->dev);
  976. ret = ttm_read_lock(&dev_priv->reservation_sem, true);
  977. if (unlikely(ret != 0)) {
  978. drm_modeset_unlock_all(dev_priv->dev);
  979. return ret;
  980. }
  981. if (!num_clips) {
  982. num_clips = 1;
  983. clips = &norect;
  984. norect.x1 = norect.y1 = 0;
  985. norect.x2 = framebuffer->width;
  986. norect.y2 = framebuffer->height;
  987. } else if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY) {
  988. num_clips /= 2;
  989. increment = 2;
  990. }
  991. switch (dev_priv->active_display_unit) {
  992. case vmw_du_screen_target:
  993. ret = vmw_kms_stdu_dma(dev_priv, NULL, &vfbd->base, NULL,
  994. clips, NULL, num_clips, increment,
  995. true, true);
  996. break;
  997. case vmw_du_screen_object:
  998. ret = vmw_kms_sou_do_dmabuf_dirty(dev_priv, &vfbd->base,
  999. clips, NULL, num_clips,
  1000. increment, true, NULL);
  1001. break;
  1002. case vmw_du_legacy:
  1003. ret = vmw_kms_ldu_do_dmabuf_dirty(dev_priv, &vfbd->base, 0, 0,
  1004. clips, num_clips, increment);
  1005. break;
  1006. default:
  1007. ret = -EINVAL;
  1008. WARN_ONCE(true, "Dirty called with invalid display system.\n");
  1009. break;
  1010. }
  1011. vmw_fifo_flush(dev_priv, false);
  1012. ttm_read_unlock(&dev_priv->reservation_sem);
  1013. drm_modeset_unlock_all(dev_priv->dev);
  1014. return ret;
  1015. }
  1016. static const struct drm_framebuffer_funcs vmw_framebuffer_dmabuf_funcs = {
  1017. .destroy = vmw_framebuffer_dmabuf_destroy,
  1018. .dirty = vmw_framebuffer_dmabuf_dirty,
  1019. };
  1020. /**
  1021. * Pin the dmabuffer to the start of vram.
  1022. */
  1023. static int vmw_framebuffer_pin(struct vmw_framebuffer *vfb)
  1024. {
  1025. struct vmw_private *dev_priv = vmw_priv(vfb->base.dev);
  1026. struct vmw_dma_buffer *buf;
  1027. int ret;
  1028. buf = vfb->dmabuf ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer :
  1029. vmw_framebuffer_to_vfbs(&vfb->base)->surface->res.backup;
  1030. if (!buf)
  1031. return 0;
  1032. switch (dev_priv->active_display_unit) {
  1033. case vmw_du_legacy:
  1034. vmw_overlay_pause_all(dev_priv);
  1035. ret = vmw_dmabuf_pin_in_start_of_vram(dev_priv, buf, false);
  1036. vmw_overlay_resume_all(dev_priv);
  1037. break;
  1038. case vmw_du_screen_object:
  1039. case vmw_du_screen_target:
  1040. if (vfb->dmabuf)
  1041. return vmw_dmabuf_pin_in_vram_or_gmr(dev_priv, buf,
  1042. false);
  1043. return vmw_dmabuf_pin_in_placement(dev_priv, buf,
  1044. &vmw_mob_placement, false);
  1045. default:
  1046. return -EINVAL;
  1047. }
  1048. return ret;
  1049. }
  1050. static int vmw_framebuffer_unpin(struct vmw_framebuffer *vfb)
  1051. {
  1052. struct vmw_private *dev_priv = vmw_priv(vfb->base.dev);
  1053. struct vmw_dma_buffer *buf;
  1054. buf = vfb->dmabuf ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer :
  1055. vmw_framebuffer_to_vfbs(&vfb->base)->surface->res.backup;
  1056. if (WARN_ON(!buf))
  1057. return 0;
  1058. return vmw_dmabuf_unpin(dev_priv, buf, false);
  1059. }
  1060. /**
  1061. * vmw_create_dmabuf_proxy - create a proxy surface for the DMA buf
  1062. *
  1063. * @dev: DRM device
  1064. * @mode_cmd: parameters for the new surface
  1065. * @dmabuf_mob: MOB backing the DMA buf
  1066. * @srf_out: newly created surface
  1067. *
  1068. * When the content FB is a DMA buf, we create a surface as a proxy to the
  1069. * same buffer. This way we can do a surface copy rather than a surface DMA.
  1070. * This is a more efficient approach
  1071. *
  1072. * RETURNS:
  1073. * 0 on success, error code otherwise
  1074. */
  1075. static int vmw_create_dmabuf_proxy(struct drm_device *dev,
  1076. const struct drm_mode_fb_cmd2 *mode_cmd,
  1077. struct vmw_dma_buffer *dmabuf_mob,
  1078. struct vmw_surface **srf_out)
  1079. {
  1080. uint32_t format;
  1081. struct drm_vmw_size content_base_size = {0};
  1082. struct vmw_resource *res;
  1083. unsigned int bytes_pp;
  1084. struct drm_format_name_buf format_name;
  1085. int ret;
  1086. switch (mode_cmd->pixel_format) {
  1087. case DRM_FORMAT_ARGB8888:
  1088. case DRM_FORMAT_XRGB8888:
  1089. format = SVGA3D_X8R8G8B8;
  1090. bytes_pp = 4;
  1091. break;
  1092. case DRM_FORMAT_RGB565:
  1093. case DRM_FORMAT_XRGB1555:
  1094. format = SVGA3D_R5G6B5;
  1095. bytes_pp = 2;
  1096. break;
  1097. case 8:
  1098. format = SVGA3D_P8;
  1099. bytes_pp = 1;
  1100. break;
  1101. default:
  1102. DRM_ERROR("Invalid framebuffer format %s\n",
  1103. drm_get_format_name(mode_cmd->pixel_format, &format_name));
  1104. return -EINVAL;
  1105. }
  1106. content_base_size.width = mode_cmd->pitches[0] / bytes_pp;
  1107. content_base_size.height = mode_cmd->height;
  1108. content_base_size.depth = 1;
  1109. ret = vmw_surface_gb_priv_define(dev,
  1110. 0, /* kernel visible only */
  1111. 0, /* flags */
  1112. format,
  1113. true, /* can be a scanout buffer */
  1114. 1, /* num of mip levels */
  1115. 0,
  1116. 0,
  1117. content_base_size,
  1118. srf_out);
  1119. if (ret) {
  1120. DRM_ERROR("Failed to allocate proxy content buffer\n");
  1121. return ret;
  1122. }
  1123. res = &(*srf_out)->res;
  1124. /* Reserve and switch the backing mob. */
  1125. mutex_lock(&res->dev_priv->cmdbuf_mutex);
  1126. (void) vmw_resource_reserve(res, false, true);
  1127. vmw_dmabuf_unreference(&res->backup);
  1128. res->backup = vmw_dmabuf_reference(dmabuf_mob);
  1129. res->backup_offset = 0;
  1130. vmw_resource_unreserve(res, false, NULL, 0);
  1131. mutex_unlock(&res->dev_priv->cmdbuf_mutex);
  1132. return 0;
  1133. }
  1134. static int vmw_kms_new_framebuffer_dmabuf(struct vmw_private *dev_priv,
  1135. struct vmw_dma_buffer *dmabuf,
  1136. struct vmw_framebuffer **out,
  1137. const struct drm_mode_fb_cmd2
  1138. *mode_cmd)
  1139. {
  1140. struct drm_device *dev = dev_priv->dev;
  1141. struct vmw_framebuffer_dmabuf *vfbd;
  1142. unsigned int requested_size;
  1143. struct drm_format_name_buf format_name;
  1144. int ret;
  1145. requested_size = mode_cmd->height * mode_cmd->pitches[0];
  1146. if (unlikely(requested_size > dmabuf->base.num_pages * PAGE_SIZE)) {
  1147. DRM_ERROR("Screen buffer object size is too small "
  1148. "for requested mode.\n");
  1149. return -EINVAL;
  1150. }
  1151. /* Limited framebuffer color depth support for screen objects */
  1152. if (dev_priv->active_display_unit == vmw_du_screen_object) {
  1153. switch (mode_cmd->pixel_format) {
  1154. case DRM_FORMAT_XRGB8888:
  1155. case DRM_FORMAT_ARGB8888:
  1156. break;
  1157. case DRM_FORMAT_XRGB1555:
  1158. case DRM_FORMAT_RGB565:
  1159. break;
  1160. default:
  1161. DRM_ERROR("Invalid pixel format: %s\n",
  1162. drm_get_format_name(mode_cmd->pixel_format, &format_name));
  1163. return -EINVAL;
  1164. }
  1165. }
  1166. vfbd = kzalloc(sizeof(*vfbd), GFP_KERNEL);
  1167. if (!vfbd) {
  1168. ret = -ENOMEM;
  1169. goto out_err1;
  1170. }
  1171. drm_helper_mode_fill_fb_struct(dev, &vfbd->base.base, mode_cmd);
  1172. vfbd->base.dmabuf = true;
  1173. vfbd->buffer = vmw_dmabuf_reference(dmabuf);
  1174. vfbd->base.user_handle = mode_cmd->handles[0];
  1175. *out = &vfbd->base;
  1176. ret = drm_framebuffer_init(dev, &vfbd->base.base,
  1177. &vmw_framebuffer_dmabuf_funcs);
  1178. if (ret)
  1179. goto out_err2;
  1180. return 0;
  1181. out_err2:
  1182. vmw_dmabuf_unreference(&dmabuf);
  1183. kfree(vfbd);
  1184. out_err1:
  1185. return ret;
  1186. }
  1187. /**
  1188. * vmw_kms_srf_ok - check if a surface can be created
  1189. *
  1190. * @width: requested width
  1191. * @height: requested height
  1192. *
  1193. * Surfaces need to be less than texture size
  1194. */
  1195. static bool
  1196. vmw_kms_srf_ok(struct vmw_private *dev_priv, uint32_t width, uint32_t height)
  1197. {
  1198. if (width > dev_priv->texture_max_width ||
  1199. height > dev_priv->texture_max_height)
  1200. return false;
  1201. return true;
  1202. }
  1203. /**
  1204. * vmw_kms_new_framebuffer - Create a new framebuffer.
  1205. *
  1206. * @dev_priv: Pointer to device private struct.
  1207. * @dmabuf: Pointer to dma buffer to wrap the kms framebuffer around.
  1208. * Either @dmabuf or @surface must be NULL.
  1209. * @surface: Pointer to a surface to wrap the kms framebuffer around.
  1210. * Either @dmabuf or @surface must be NULL.
  1211. * @only_2d: No presents will occur to this dma buffer based framebuffer. This
  1212. * Helps the code to do some important optimizations.
  1213. * @mode_cmd: Frame-buffer metadata.
  1214. */
  1215. struct vmw_framebuffer *
  1216. vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
  1217. struct vmw_dma_buffer *dmabuf,
  1218. struct vmw_surface *surface,
  1219. bool only_2d,
  1220. const struct drm_mode_fb_cmd2 *mode_cmd)
  1221. {
  1222. struct vmw_framebuffer *vfb = NULL;
  1223. bool is_dmabuf_proxy = false;
  1224. int ret;
  1225. /*
  1226. * We cannot use the SurfaceDMA command in an non-accelerated VM,
  1227. * therefore, wrap the DMA buf in a surface so we can use the
  1228. * SurfaceCopy command.
  1229. */
  1230. if (vmw_kms_srf_ok(dev_priv, mode_cmd->width, mode_cmd->height) &&
  1231. dmabuf && only_2d &&
  1232. dev_priv->active_display_unit == vmw_du_screen_target) {
  1233. ret = vmw_create_dmabuf_proxy(dev_priv->dev, mode_cmd,
  1234. dmabuf, &surface);
  1235. if (ret)
  1236. return ERR_PTR(ret);
  1237. is_dmabuf_proxy = true;
  1238. }
  1239. /* Create the new framebuffer depending one what we have */
  1240. if (surface) {
  1241. ret = vmw_kms_new_framebuffer_surface(dev_priv, surface, &vfb,
  1242. mode_cmd,
  1243. is_dmabuf_proxy);
  1244. /*
  1245. * vmw_create_dmabuf_proxy() adds a reference that is no longer
  1246. * needed
  1247. */
  1248. if (is_dmabuf_proxy)
  1249. vmw_surface_unreference(&surface);
  1250. } else if (dmabuf) {
  1251. ret = vmw_kms_new_framebuffer_dmabuf(dev_priv, dmabuf, &vfb,
  1252. mode_cmd);
  1253. } else {
  1254. BUG();
  1255. }
  1256. if (ret)
  1257. return ERR_PTR(ret);
  1258. vfb->pin = vmw_framebuffer_pin;
  1259. vfb->unpin = vmw_framebuffer_unpin;
  1260. return vfb;
  1261. }
  1262. /*
  1263. * Generic Kernel modesetting functions
  1264. */
  1265. static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
  1266. struct drm_file *file_priv,
  1267. const struct drm_mode_fb_cmd2 *mode_cmd)
  1268. {
  1269. struct vmw_private *dev_priv = vmw_priv(dev);
  1270. struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
  1271. struct vmw_framebuffer *vfb = NULL;
  1272. struct vmw_surface *surface = NULL;
  1273. struct vmw_dma_buffer *bo = NULL;
  1274. struct ttm_base_object *user_obj;
  1275. int ret;
  1276. /**
  1277. * This code should be conditioned on Screen Objects not being used.
  1278. * If screen objects are used, we can allocate a GMR to hold the
  1279. * requested framebuffer.
  1280. */
  1281. if (!vmw_kms_validate_mode_vram(dev_priv,
  1282. mode_cmd->pitches[0],
  1283. mode_cmd->height)) {
  1284. DRM_ERROR("Requested mode exceed bounding box limit.\n");
  1285. return ERR_PTR(-ENOMEM);
  1286. }
  1287. /*
  1288. * Take a reference on the user object of the resource
  1289. * backing the kms fb. This ensures that user-space handle
  1290. * lookups on that resource will always work as long as
  1291. * it's registered with a kms framebuffer. This is important,
  1292. * since vmw_execbuf_process identifies resources in the
  1293. * command stream using user-space handles.
  1294. */
  1295. user_obj = ttm_base_object_lookup(tfile, mode_cmd->handles[0]);
  1296. if (unlikely(user_obj == NULL)) {
  1297. DRM_ERROR("Could not locate requested kms frame buffer.\n");
  1298. return ERR_PTR(-ENOENT);
  1299. }
  1300. /**
  1301. * End conditioned code.
  1302. */
  1303. /* returns either a dmabuf or surface */
  1304. ret = vmw_user_lookup_handle(dev_priv, tfile,
  1305. mode_cmd->handles[0],
  1306. &surface, &bo);
  1307. if (ret)
  1308. goto err_out;
  1309. if (!bo &&
  1310. !vmw_kms_srf_ok(dev_priv, mode_cmd->width, mode_cmd->height)) {
  1311. DRM_ERROR("Surface size cannot exceed %dx%d",
  1312. dev_priv->texture_max_width,
  1313. dev_priv->texture_max_height);
  1314. goto err_out;
  1315. }
  1316. vfb = vmw_kms_new_framebuffer(dev_priv, bo, surface,
  1317. !(dev_priv->capabilities & SVGA_CAP_3D),
  1318. mode_cmd);
  1319. if (IS_ERR(vfb)) {
  1320. ret = PTR_ERR(vfb);
  1321. goto err_out;
  1322. }
  1323. err_out:
  1324. /* vmw_user_lookup_handle takes one ref so does new_fb */
  1325. if (bo)
  1326. vmw_dmabuf_unreference(&bo);
  1327. if (surface)
  1328. vmw_surface_unreference(&surface);
  1329. if (ret) {
  1330. DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret);
  1331. ttm_base_object_unref(&user_obj);
  1332. return ERR_PTR(ret);
  1333. } else
  1334. vfb->user_obj = user_obj;
  1335. return &vfb->base;
  1336. }
  1337. /**
  1338. * vmw_kms_atomic_check_modeset- validate state object for modeset changes
  1339. *
  1340. * @dev: DRM device
  1341. * @state: the driver state object
  1342. *
  1343. * This is a simple wrapper around drm_atomic_helper_check_modeset() for
  1344. * us to assign a value to mode->crtc_clock so that
  1345. * drm_calc_timestamping_constants() won't throw an error message
  1346. *
  1347. * RETURNS
  1348. * Zero for success or -errno
  1349. */
  1350. int
  1351. vmw_kms_atomic_check_modeset(struct drm_device *dev,
  1352. struct drm_atomic_state *state)
  1353. {
  1354. struct drm_crtc_state *crtc_state;
  1355. struct drm_crtc *crtc;
  1356. struct vmw_private *dev_priv = vmw_priv(dev);
  1357. int i;
  1358. for_each_crtc_in_state(state, crtc, crtc_state, i) {
  1359. unsigned long requested_bb_mem = 0;
  1360. if (dev_priv->active_display_unit == vmw_du_screen_target) {
  1361. if (crtc->primary->fb) {
  1362. int cpp = crtc->primary->fb->pitches[0] /
  1363. crtc->primary->fb->width;
  1364. requested_bb_mem += crtc->mode.hdisplay * cpp *
  1365. crtc->mode.vdisplay;
  1366. }
  1367. if (requested_bb_mem > dev_priv->prim_bb_mem)
  1368. return -EINVAL;
  1369. }
  1370. }
  1371. return drm_atomic_helper_check(dev, state);
  1372. }
  1373. static const struct drm_mode_config_funcs vmw_kms_funcs = {
  1374. .fb_create = vmw_kms_fb_create,
  1375. .atomic_check = vmw_kms_atomic_check_modeset,
  1376. .atomic_commit = drm_atomic_helper_commit,
  1377. };
  1378. static int vmw_kms_generic_present(struct vmw_private *dev_priv,
  1379. struct drm_file *file_priv,
  1380. struct vmw_framebuffer *vfb,
  1381. struct vmw_surface *surface,
  1382. uint32_t sid,
  1383. int32_t destX, int32_t destY,
  1384. struct drm_vmw_rect *clips,
  1385. uint32_t num_clips)
  1386. {
  1387. return vmw_kms_sou_do_surface_dirty(dev_priv, vfb, NULL, clips,
  1388. &surface->res, destX, destY,
  1389. num_clips, 1, NULL);
  1390. }
  1391. int vmw_kms_present(struct vmw_private *dev_priv,
  1392. struct drm_file *file_priv,
  1393. struct vmw_framebuffer *vfb,
  1394. struct vmw_surface *surface,
  1395. uint32_t sid,
  1396. int32_t destX, int32_t destY,
  1397. struct drm_vmw_rect *clips,
  1398. uint32_t num_clips)
  1399. {
  1400. int ret;
  1401. switch (dev_priv->active_display_unit) {
  1402. case vmw_du_screen_target:
  1403. ret = vmw_kms_stdu_surface_dirty(dev_priv, vfb, NULL, clips,
  1404. &surface->res, destX, destY,
  1405. num_clips, 1, NULL);
  1406. break;
  1407. case vmw_du_screen_object:
  1408. ret = vmw_kms_generic_present(dev_priv, file_priv, vfb, surface,
  1409. sid, destX, destY, clips,
  1410. num_clips);
  1411. break;
  1412. default:
  1413. WARN_ONCE(true,
  1414. "Present called with invalid display system.\n");
  1415. ret = -ENOSYS;
  1416. break;
  1417. }
  1418. if (ret)
  1419. return ret;
  1420. vmw_fifo_flush(dev_priv, false);
  1421. return 0;
  1422. }
  1423. static void
  1424. vmw_kms_create_hotplug_mode_update_property(struct vmw_private *dev_priv)
  1425. {
  1426. if (dev_priv->hotplug_mode_update_property)
  1427. return;
  1428. dev_priv->hotplug_mode_update_property =
  1429. drm_property_create_range(dev_priv->dev,
  1430. DRM_MODE_PROP_IMMUTABLE,
  1431. "hotplug_mode_update", 0, 1);
  1432. if (!dev_priv->hotplug_mode_update_property)
  1433. return;
  1434. }
  1435. int vmw_kms_init(struct vmw_private *dev_priv)
  1436. {
  1437. struct drm_device *dev = dev_priv->dev;
  1438. int ret;
  1439. drm_mode_config_init(dev);
  1440. dev->mode_config.funcs = &vmw_kms_funcs;
  1441. dev->mode_config.min_width = 1;
  1442. dev->mode_config.min_height = 1;
  1443. dev->mode_config.max_width = dev_priv->texture_max_width;
  1444. dev->mode_config.max_height = dev_priv->texture_max_height;
  1445. drm_mode_create_suggested_offset_properties(dev);
  1446. vmw_kms_create_hotplug_mode_update_property(dev_priv);
  1447. ret = vmw_kms_stdu_init_display(dev_priv);
  1448. if (ret) {
  1449. ret = vmw_kms_sou_init_display(dev_priv);
  1450. if (ret) /* Fallback */
  1451. ret = vmw_kms_ldu_init_display(dev_priv);
  1452. }
  1453. return ret;
  1454. }
  1455. int vmw_kms_close(struct vmw_private *dev_priv)
  1456. {
  1457. int ret;
  1458. /*
  1459. * Docs says we should take the lock before calling this function
  1460. * but since it destroys encoders and our destructor calls
  1461. * drm_encoder_cleanup which takes the lock we deadlock.
  1462. */
  1463. drm_mode_config_cleanup(dev_priv->dev);
  1464. if (dev_priv->active_display_unit == vmw_du_screen_object)
  1465. ret = vmw_kms_sou_close_display(dev_priv);
  1466. else if (dev_priv->active_display_unit == vmw_du_screen_target)
  1467. ret = vmw_kms_stdu_close_display(dev_priv);
  1468. else
  1469. ret = vmw_kms_ldu_close_display(dev_priv);
  1470. return ret;
  1471. }
  1472. int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
  1473. struct drm_file *file_priv)
  1474. {
  1475. struct drm_vmw_cursor_bypass_arg *arg = data;
  1476. struct vmw_display_unit *du;
  1477. struct drm_crtc *crtc;
  1478. int ret = 0;
  1479. mutex_lock(&dev->mode_config.mutex);
  1480. if (arg->flags & DRM_VMW_CURSOR_BYPASS_ALL) {
  1481. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1482. du = vmw_crtc_to_du(crtc);
  1483. du->hotspot_x = arg->xhot;
  1484. du->hotspot_y = arg->yhot;
  1485. }
  1486. mutex_unlock(&dev->mode_config.mutex);
  1487. return 0;
  1488. }
  1489. crtc = drm_crtc_find(dev, arg->crtc_id);
  1490. if (!crtc) {
  1491. ret = -ENOENT;
  1492. goto out;
  1493. }
  1494. du = vmw_crtc_to_du(crtc);
  1495. du->hotspot_x = arg->xhot;
  1496. du->hotspot_y = arg->yhot;
  1497. out:
  1498. mutex_unlock(&dev->mode_config.mutex);
  1499. return ret;
  1500. }
  1501. int vmw_kms_write_svga(struct vmw_private *vmw_priv,
  1502. unsigned width, unsigned height, unsigned pitch,
  1503. unsigned bpp, unsigned depth)
  1504. {
  1505. if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK)
  1506. vmw_write(vmw_priv, SVGA_REG_PITCHLOCK, pitch);
  1507. else if (vmw_fifo_have_pitchlock(vmw_priv))
  1508. vmw_mmio_write(pitch, vmw_priv->mmio_virt +
  1509. SVGA_FIFO_PITCHLOCK);
  1510. vmw_write(vmw_priv, SVGA_REG_WIDTH, width);
  1511. vmw_write(vmw_priv, SVGA_REG_HEIGHT, height);
  1512. vmw_write(vmw_priv, SVGA_REG_BITS_PER_PIXEL, bpp);
  1513. if (vmw_read(vmw_priv, SVGA_REG_DEPTH) != depth) {
  1514. DRM_ERROR("Invalid depth %u for %u bpp, host expects %u\n",
  1515. depth, bpp, vmw_read(vmw_priv, SVGA_REG_DEPTH));
  1516. return -EINVAL;
  1517. }
  1518. return 0;
  1519. }
  1520. int vmw_kms_save_vga(struct vmw_private *vmw_priv)
  1521. {
  1522. struct vmw_vga_topology_state *save;
  1523. uint32_t i;
  1524. vmw_priv->vga_width = vmw_read(vmw_priv, SVGA_REG_WIDTH);
  1525. vmw_priv->vga_height = vmw_read(vmw_priv, SVGA_REG_HEIGHT);
  1526. vmw_priv->vga_bpp = vmw_read(vmw_priv, SVGA_REG_BITS_PER_PIXEL);
  1527. if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK)
  1528. vmw_priv->vga_pitchlock =
  1529. vmw_read(vmw_priv, SVGA_REG_PITCHLOCK);
  1530. else if (vmw_fifo_have_pitchlock(vmw_priv))
  1531. vmw_priv->vga_pitchlock = vmw_mmio_read(vmw_priv->mmio_virt +
  1532. SVGA_FIFO_PITCHLOCK);
  1533. if (!(vmw_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY))
  1534. return 0;
  1535. vmw_priv->num_displays = vmw_read(vmw_priv,
  1536. SVGA_REG_NUM_GUEST_DISPLAYS);
  1537. if (vmw_priv->num_displays == 0)
  1538. vmw_priv->num_displays = 1;
  1539. for (i = 0; i < vmw_priv->num_displays; ++i) {
  1540. save = &vmw_priv->vga_save[i];
  1541. vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, i);
  1542. save->primary = vmw_read(vmw_priv, SVGA_REG_DISPLAY_IS_PRIMARY);
  1543. save->pos_x = vmw_read(vmw_priv, SVGA_REG_DISPLAY_POSITION_X);
  1544. save->pos_y = vmw_read(vmw_priv, SVGA_REG_DISPLAY_POSITION_Y);
  1545. save->width = vmw_read(vmw_priv, SVGA_REG_DISPLAY_WIDTH);
  1546. save->height = vmw_read(vmw_priv, SVGA_REG_DISPLAY_HEIGHT);
  1547. vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID);
  1548. if (i == 0 && vmw_priv->num_displays == 1 &&
  1549. save->width == 0 && save->height == 0) {
  1550. /*
  1551. * It should be fairly safe to assume that these
  1552. * values are uninitialized.
  1553. */
  1554. save->width = vmw_priv->vga_width - save->pos_x;
  1555. save->height = vmw_priv->vga_height - save->pos_y;
  1556. }
  1557. }
  1558. return 0;
  1559. }
  1560. int vmw_kms_restore_vga(struct vmw_private *vmw_priv)
  1561. {
  1562. struct vmw_vga_topology_state *save;
  1563. uint32_t i;
  1564. vmw_write(vmw_priv, SVGA_REG_WIDTH, vmw_priv->vga_width);
  1565. vmw_write(vmw_priv, SVGA_REG_HEIGHT, vmw_priv->vga_height);
  1566. vmw_write(vmw_priv, SVGA_REG_BITS_PER_PIXEL, vmw_priv->vga_bpp);
  1567. if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK)
  1568. vmw_write(vmw_priv, SVGA_REG_PITCHLOCK,
  1569. vmw_priv->vga_pitchlock);
  1570. else if (vmw_fifo_have_pitchlock(vmw_priv))
  1571. vmw_mmio_write(vmw_priv->vga_pitchlock,
  1572. vmw_priv->mmio_virt + SVGA_FIFO_PITCHLOCK);
  1573. if (!(vmw_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY))
  1574. return 0;
  1575. for (i = 0; i < vmw_priv->num_displays; ++i) {
  1576. save = &vmw_priv->vga_save[i];
  1577. vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, i);
  1578. vmw_write(vmw_priv, SVGA_REG_DISPLAY_IS_PRIMARY, save->primary);
  1579. vmw_write(vmw_priv, SVGA_REG_DISPLAY_POSITION_X, save->pos_x);
  1580. vmw_write(vmw_priv, SVGA_REG_DISPLAY_POSITION_Y, save->pos_y);
  1581. vmw_write(vmw_priv, SVGA_REG_DISPLAY_WIDTH, save->width);
  1582. vmw_write(vmw_priv, SVGA_REG_DISPLAY_HEIGHT, save->height);
  1583. vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID);
  1584. }
  1585. return 0;
  1586. }
  1587. bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
  1588. uint32_t pitch,
  1589. uint32_t height)
  1590. {
  1591. return ((u64) pitch * (u64) height) < (u64)
  1592. ((dev_priv->active_display_unit == vmw_du_screen_target) ?
  1593. dev_priv->prim_bb_mem : dev_priv->vram_size);
  1594. }
  1595. /**
  1596. * Function called by DRM code called with vbl_lock held.
  1597. */
  1598. u32 vmw_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
  1599. {
  1600. return 0;
  1601. }
  1602. /**
  1603. * Function called by DRM code called with vbl_lock held.
  1604. */
  1605. int vmw_enable_vblank(struct drm_device *dev, unsigned int pipe)
  1606. {
  1607. return -ENOSYS;
  1608. }
  1609. /**
  1610. * Function called by DRM code called with vbl_lock held.
  1611. */
  1612. void vmw_disable_vblank(struct drm_device *dev, unsigned int pipe)
  1613. {
  1614. }
  1615. /*
  1616. * Small shared kms functions.
  1617. */
  1618. static int vmw_du_update_layout(struct vmw_private *dev_priv, unsigned num,
  1619. struct drm_vmw_rect *rects)
  1620. {
  1621. struct drm_device *dev = dev_priv->dev;
  1622. struct vmw_display_unit *du;
  1623. struct drm_connector *con;
  1624. mutex_lock(&dev->mode_config.mutex);
  1625. #if 0
  1626. {
  1627. unsigned int i;
  1628. DRM_INFO("%s: new layout ", __func__);
  1629. for (i = 0; i < num; i++)
  1630. DRM_INFO("(%i, %i %ux%u) ", rects[i].x, rects[i].y,
  1631. rects[i].w, rects[i].h);
  1632. DRM_INFO("\n");
  1633. }
  1634. #endif
  1635. list_for_each_entry(con, &dev->mode_config.connector_list, head) {
  1636. du = vmw_connector_to_du(con);
  1637. if (num > du->unit) {
  1638. du->pref_width = rects[du->unit].w;
  1639. du->pref_height = rects[du->unit].h;
  1640. du->pref_active = true;
  1641. du->gui_x = rects[du->unit].x;
  1642. du->gui_y = rects[du->unit].y;
  1643. drm_object_property_set_value
  1644. (&con->base, dev->mode_config.suggested_x_property,
  1645. du->gui_x);
  1646. drm_object_property_set_value
  1647. (&con->base, dev->mode_config.suggested_y_property,
  1648. du->gui_y);
  1649. } else {
  1650. du->pref_width = 800;
  1651. du->pref_height = 600;
  1652. du->pref_active = false;
  1653. drm_object_property_set_value
  1654. (&con->base, dev->mode_config.suggested_x_property,
  1655. 0);
  1656. drm_object_property_set_value
  1657. (&con->base, dev->mode_config.suggested_y_property,
  1658. 0);
  1659. }
  1660. con->status = vmw_du_connector_detect(con, true);
  1661. }
  1662. mutex_unlock(&dev->mode_config.mutex);
  1663. drm_sysfs_hotplug_event(dev);
  1664. return 0;
  1665. }
  1666. int vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
  1667. u16 *r, u16 *g, u16 *b,
  1668. uint32_t size,
  1669. struct drm_modeset_acquire_ctx *ctx)
  1670. {
  1671. struct vmw_private *dev_priv = vmw_priv(crtc->dev);
  1672. int i;
  1673. for (i = 0; i < size; i++) {
  1674. DRM_DEBUG("%d r/g/b = 0x%04x / 0x%04x / 0x%04x\n", i,
  1675. r[i], g[i], b[i]);
  1676. vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 0, r[i] >> 8);
  1677. vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 1, g[i] >> 8);
  1678. vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 2, b[i] >> 8);
  1679. }
  1680. return 0;
  1681. }
  1682. int vmw_du_connector_dpms(struct drm_connector *connector, int mode)
  1683. {
  1684. return 0;
  1685. }
  1686. enum drm_connector_status
  1687. vmw_du_connector_detect(struct drm_connector *connector, bool force)
  1688. {
  1689. uint32_t num_displays;
  1690. struct drm_device *dev = connector->dev;
  1691. struct vmw_private *dev_priv = vmw_priv(dev);
  1692. struct vmw_display_unit *du = vmw_connector_to_du(connector);
  1693. num_displays = vmw_read(dev_priv, SVGA_REG_NUM_DISPLAYS);
  1694. return ((vmw_connector_to_du(connector)->unit < num_displays &&
  1695. du->pref_active) ?
  1696. connector_status_connected : connector_status_disconnected);
  1697. }
  1698. static struct drm_display_mode vmw_kms_connector_builtin[] = {
  1699. /* 640x480@60Hz */
  1700. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
  1701. 752, 800, 0, 480, 489, 492, 525, 0,
  1702. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  1703. /* 800x600@60Hz */
  1704. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
  1705. 968, 1056, 0, 600, 601, 605, 628, 0,
  1706. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1707. /* 1024x768@60Hz */
  1708. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
  1709. 1184, 1344, 0, 768, 771, 777, 806, 0,
  1710. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  1711. /* 1152x864@75Hz */
  1712. { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
  1713. 1344, 1600, 0, 864, 865, 868, 900, 0,
  1714. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1715. /* 1280x768@60Hz */
  1716. { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
  1717. 1472, 1664, 0, 768, 771, 778, 798, 0,
  1718. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1719. /* 1280x800@60Hz */
  1720. { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
  1721. 1480, 1680, 0, 800, 803, 809, 831, 0,
  1722. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  1723. /* 1280x960@60Hz */
  1724. { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
  1725. 1488, 1800, 0, 960, 961, 964, 1000, 0,
  1726. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1727. /* 1280x1024@60Hz */
  1728. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
  1729. 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
  1730. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1731. /* 1360x768@60Hz */
  1732. { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
  1733. 1536, 1792, 0, 768, 771, 777, 795, 0,
  1734. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1735. /* 1440x1050@60Hz */
  1736. { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
  1737. 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
  1738. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1739. /* 1440x900@60Hz */
  1740. { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
  1741. 1672, 1904, 0, 900, 903, 909, 934, 0,
  1742. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1743. /* 1600x1200@60Hz */
  1744. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
  1745. 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
  1746. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1747. /* 1680x1050@60Hz */
  1748. { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
  1749. 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
  1750. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1751. /* 1792x1344@60Hz */
  1752. { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
  1753. 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
  1754. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1755. /* 1853x1392@60Hz */
  1756. { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
  1757. 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
  1758. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1759. /* 1920x1200@60Hz */
  1760. { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
  1761. 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
  1762. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1763. /* 1920x1440@60Hz */
  1764. { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
  1765. 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
  1766. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1767. /* 2560x1600@60Hz */
  1768. { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
  1769. 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
  1770. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1771. /* Terminate */
  1772. { DRM_MODE("", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) },
  1773. };
  1774. /**
  1775. * vmw_guess_mode_timing - Provide fake timings for a
  1776. * 60Hz vrefresh mode.
  1777. *
  1778. * @mode - Pointer to a struct drm_display_mode with hdisplay and vdisplay
  1779. * members filled in.
  1780. */
  1781. void vmw_guess_mode_timing(struct drm_display_mode *mode)
  1782. {
  1783. mode->hsync_start = mode->hdisplay + 50;
  1784. mode->hsync_end = mode->hsync_start + 50;
  1785. mode->htotal = mode->hsync_end + 50;
  1786. mode->vsync_start = mode->vdisplay + 50;
  1787. mode->vsync_end = mode->vsync_start + 50;
  1788. mode->vtotal = mode->vsync_end + 50;
  1789. mode->clock = (u32)mode->htotal * (u32)mode->vtotal / 100 * 6;
  1790. mode->vrefresh = drm_mode_vrefresh(mode);
  1791. }
  1792. int vmw_du_connector_fill_modes(struct drm_connector *connector,
  1793. uint32_t max_width, uint32_t max_height)
  1794. {
  1795. struct vmw_display_unit *du = vmw_connector_to_du(connector);
  1796. struct drm_device *dev = connector->dev;
  1797. struct vmw_private *dev_priv = vmw_priv(dev);
  1798. struct drm_display_mode *mode = NULL;
  1799. struct drm_display_mode *bmode;
  1800. struct drm_display_mode prefmode = { DRM_MODE("preferred",
  1801. DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
  1802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1803. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC)
  1804. };
  1805. int i;
  1806. u32 assumed_bpp = 4;
  1807. if (dev_priv->assume_16bpp)
  1808. assumed_bpp = 2;
  1809. if (dev_priv->active_display_unit == vmw_du_screen_target) {
  1810. max_width = min(max_width, dev_priv->stdu_max_width);
  1811. max_width = min(max_width, dev_priv->texture_max_width);
  1812. max_height = min(max_height, dev_priv->stdu_max_height);
  1813. max_height = min(max_height, dev_priv->texture_max_height);
  1814. }
  1815. /* Add preferred mode */
  1816. mode = drm_mode_duplicate(dev, &prefmode);
  1817. if (!mode)
  1818. return 0;
  1819. mode->hdisplay = du->pref_width;
  1820. mode->vdisplay = du->pref_height;
  1821. vmw_guess_mode_timing(mode);
  1822. if (vmw_kms_validate_mode_vram(dev_priv,
  1823. mode->hdisplay * assumed_bpp,
  1824. mode->vdisplay)) {
  1825. drm_mode_probed_add(connector, mode);
  1826. } else {
  1827. drm_mode_destroy(dev, mode);
  1828. mode = NULL;
  1829. }
  1830. if (du->pref_mode) {
  1831. list_del_init(&du->pref_mode->head);
  1832. drm_mode_destroy(dev, du->pref_mode);
  1833. }
  1834. /* mode might be null here, this is intended */
  1835. du->pref_mode = mode;
  1836. for (i = 0; vmw_kms_connector_builtin[i].type != 0; i++) {
  1837. bmode = &vmw_kms_connector_builtin[i];
  1838. if (bmode->hdisplay > max_width ||
  1839. bmode->vdisplay > max_height)
  1840. continue;
  1841. if (!vmw_kms_validate_mode_vram(dev_priv,
  1842. bmode->hdisplay * assumed_bpp,
  1843. bmode->vdisplay))
  1844. continue;
  1845. mode = drm_mode_duplicate(dev, bmode);
  1846. if (!mode)
  1847. return 0;
  1848. mode->vrefresh = drm_mode_vrefresh(mode);
  1849. drm_mode_probed_add(connector, mode);
  1850. }
  1851. drm_mode_connector_list_update(connector);
  1852. /* Move the prefered mode first, help apps pick the right mode. */
  1853. drm_mode_sort(&connector->modes);
  1854. return 1;
  1855. }
  1856. int vmw_du_connector_set_property(struct drm_connector *connector,
  1857. struct drm_property *property,
  1858. uint64_t val)
  1859. {
  1860. struct vmw_display_unit *du = vmw_connector_to_du(connector);
  1861. struct vmw_private *dev_priv = vmw_priv(connector->dev);
  1862. if (property == dev_priv->implicit_placement_property)
  1863. du->is_implicit = val;
  1864. return 0;
  1865. }
  1866. /**
  1867. * vmw_du_connector_atomic_set_property - Atomic version of get property
  1868. *
  1869. * @crtc - crtc the property is associated with
  1870. *
  1871. * Returns:
  1872. * Zero on success, negative errno on failure.
  1873. */
  1874. int
  1875. vmw_du_connector_atomic_set_property(struct drm_connector *connector,
  1876. struct drm_connector_state *state,
  1877. struct drm_property *property,
  1878. uint64_t val)
  1879. {
  1880. struct vmw_private *dev_priv = vmw_priv(connector->dev);
  1881. struct vmw_connector_state *vcs = vmw_connector_state_to_vcs(state);
  1882. struct vmw_display_unit *du = vmw_connector_to_du(connector);
  1883. if (property == dev_priv->implicit_placement_property) {
  1884. vcs->is_implicit = val;
  1885. /*
  1886. * We should really be doing a drm_atomic_commit() to
  1887. * commit the new state, but since this doesn't cause
  1888. * an immedate state change, this is probably ok
  1889. */
  1890. du->is_implicit = vcs->is_implicit;
  1891. } else {
  1892. return -EINVAL;
  1893. }
  1894. return 0;
  1895. }
  1896. /**
  1897. * vmw_du_connector_atomic_get_property - Atomic version of get property
  1898. *
  1899. * @connector - connector the property is associated with
  1900. *
  1901. * Returns:
  1902. * Zero on success, negative errno on failure.
  1903. */
  1904. int
  1905. vmw_du_connector_atomic_get_property(struct drm_connector *connector,
  1906. const struct drm_connector_state *state,
  1907. struct drm_property *property,
  1908. uint64_t *val)
  1909. {
  1910. struct vmw_private *dev_priv = vmw_priv(connector->dev);
  1911. struct vmw_connector_state *vcs = vmw_connector_state_to_vcs(state);
  1912. if (property == dev_priv->implicit_placement_property)
  1913. *val = vcs->is_implicit;
  1914. else {
  1915. DRM_ERROR("Invalid Property %s\n", property->name);
  1916. return -EINVAL;
  1917. }
  1918. return 0;
  1919. }
  1920. int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
  1921. struct drm_file *file_priv)
  1922. {
  1923. struct vmw_private *dev_priv = vmw_priv(dev);
  1924. struct drm_vmw_update_layout_arg *arg =
  1925. (struct drm_vmw_update_layout_arg *)data;
  1926. void __user *user_rects;
  1927. struct drm_vmw_rect *rects;
  1928. unsigned rects_size;
  1929. int ret;
  1930. int i;
  1931. u64 total_pixels = 0;
  1932. struct drm_mode_config *mode_config = &dev->mode_config;
  1933. struct drm_vmw_rect bounding_box = {0};
  1934. if (!arg->num_outputs) {
  1935. struct drm_vmw_rect def_rect = {0, 0, 800, 600};
  1936. vmw_du_update_layout(dev_priv, 1, &def_rect);
  1937. return 0;
  1938. }
  1939. rects_size = arg->num_outputs * sizeof(struct drm_vmw_rect);
  1940. rects = kcalloc(arg->num_outputs, sizeof(struct drm_vmw_rect),
  1941. GFP_KERNEL);
  1942. if (unlikely(!rects))
  1943. return -ENOMEM;
  1944. user_rects = (void __user *)(unsigned long)arg->rects;
  1945. ret = copy_from_user(rects, user_rects, rects_size);
  1946. if (unlikely(ret != 0)) {
  1947. DRM_ERROR("Failed to get rects.\n");
  1948. ret = -EFAULT;
  1949. goto out_free;
  1950. }
  1951. for (i = 0; i < arg->num_outputs; ++i) {
  1952. if (rects[i].x < 0 ||
  1953. rects[i].y < 0 ||
  1954. rects[i].x + rects[i].w > mode_config->max_width ||
  1955. rects[i].y + rects[i].h > mode_config->max_height) {
  1956. DRM_ERROR("Invalid GUI layout.\n");
  1957. ret = -EINVAL;
  1958. goto out_free;
  1959. }
  1960. /*
  1961. * bounding_box.w and bunding_box.h are used as
  1962. * lower-right coordinates
  1963. */
  1964. if (rects[i].x + rects[i].w > bounding_box.w)
  1965. bounding_box.w = rects[i].x + rects[i].w;
  1966. if (rects[i].y + rects[i].h > bounding_box.h)
  1967. bounding_box.h = rects[i].y + rects[i].h;
  1968. total_pixels += (u64) rects[i].w * (u64) rects[i].h;
  1969. }
  1970. if (dev_priv->active_display_unit == vmw_du_screen_target) {
  1971. /*
  1972. * For Screen Targets, the limits for a toplogy are:
  1973. * 1. Bounding box (assuming 32bpp) must be < prim_bb_mem
  1974. * 2. Total pixels (assuming 32bpp) must be < prim_bb_mem
  1975. */
  1976. u64 bb_mem = (u64) bounding_box.w * bounding_box.h * 4;
  1977. u64 pixel_mem = total_pixels * 4;
  1978. if (bb_mem > dev_priv->prim_bb_mem) {
  1979. DRM_ERROR("Topology is beyond supported limits.\n");
  1980. ret = -EINVAL;
  1981. goto out_free;
  1982. }
  1983. if (pixel_mem > dev_priv->prim_bb_mem) {
  1984. DRM_ERROR("Combined output size too large\n");
  1985. ret = -EINVAL;
  1986. goto out_free;
  1987. }
  1988. }
  1989. vmw_du_update_layout(dev_priv, arg->num_outputs, rects);
  1990. out_free:
  1991. kfree(rects);
  1992. return ret;
  1993. }
  1994. /**
  1995. * vmw_kms_helper_dirty - Helper to build commands and perform actions based
  1996. * on a set of cliprects and a set of display units.
  1997. *
  1998. * @dev_priv: Pointer to a device private structure.
  1999. * @framebuffer: Pointer to the framebuffer on which to perform the actions.
  2000. * @clips: A set of struct drm_clip_rect. Either this os @vclips must be NULL.
  2001. * Cliprects are given in framebuffer coordinates.
  2002. * @vclips: A set of struct drm_vmw_rect cliprects. Either this or @clips must
  2003. * be NULL. Cliprects are given in source coordinates.
  2004. * @dest_x: X coordinate offset for the crtc / destination clip rects.
  2005. * @dest_y: Y coordinate offset for the crtc / destination clip rects.
  2006. * @num_clips: Number of cliprects in the @clips or @vclips array.
  2007. * @increment: Integer with which to increment the clip counter when looping.
  2008. * Used to skip a predetermined number of clip rects.
  2009. * @dirty: Closure structure. See the description of struct vmw_kms_dirty.
  2010. */
  2011. int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
  2012. struct vmw_framebuffer *framebuffer,
  2013. const struct drm_clip_rect *clips,
  2014. const struct drm_vmw_rect *vclips,
  2015. s32 dest_x, s32 dest_y,
  2016. int num_clips,
  2017. int increment,
  2018. struct vmw_kms_dirty *dirty)
  2019. {
  2020. struct vmw_display_unit *units[VMWGFX_NUM_DISPLAY_UNITS];
  2021. struct drm_crtc *crtc;
  2022. u32 num_units = 0;
  2023. u32 i, k;
  2024. dirty->dev_priv = dev_priv;
  2025. list_for_each_entry(crtc, &dev_priv->dev->mode_config.crtc_list, head) {
  2026. if (crtc->primary->fb != &framebuffer->base)
  2027. continue;
  2028. units[num_units++] = vmw_crtc_to_du(crtc);
  2029. }
  2030. for (k = 0; k < num_units; k++) {
  2031. struct vmw_display_unit *unit = units[k];
  2032. s32 crtc_x = unit->crtc.x;
  2033. s32 crtc_y = unit->crtc.y;
  2034. s32 crtc_width = unit->crtc.mode.hdisplay;
  2035. s32 crtc_height = unit->crtc.mode.vdisplay;
  2036. const struct drm_clip_rect *clips_ptr = clips;
  2037. const struct drm_vmw_rect *vclips_ptr = vclips;
  2038. dirty->unit = unit;
  2039. if (dirty->fifo_reserve_size > 0) {
  2040. dirty->cmd = vmw_fifo_reserve(dev_priv,
  2041. dirty->fifo_reserve_size);
  2042. if (!dirty->cmd) {
  2043. DRM_ERROR("Couldn't reserve fifo space "
  2044. "for dirty blits.\n");
  2045. return -ENOMEM;
  2046. }
  2047. memset(dirty->cmd, 0, dirty->fifo_reserve_size);
  2048. }
  2049. dirty->num_hits = 0;
  2050. for (i = 0; i < num_clips; i++, clips_ptr += increment,
  2051. vclips_ptr += increment) {
  2052. s32 clip_left;
  2053. s32 clip_top;
  2054. /*
  2055. * Select clip array type. Note that integer type
  2056. * in @clips is unsigned short, whereas in @vclips
  2057. * it's 32-bit.
  2058. */
  2059. if (clips) {
  2060. dirty->fb_x = (s32) clips_ptr->x1;
  2061. dirty->fb_y = (s32) clips_ptr->y1;
  2062. dirty->unit_x2 = (s32) clips_ptr->x2 + dest_x -
  2063. crtc_x;
  2064. dirty->unit_y2 = (s32) clips_ptr->y2 + dest_y -
  2065. crtc_y;
  2066. } else {
  2067. dirty->fb_x = vclips_ptr->x;
  2068. dirty->fb_y = vclips_ptr->y;
  2069. dirty->unit_x2 = dirty->fb_x + vclips_ptr->w +
  2070. dest_x - crtc_x;
  2071. dirty->unit_y2 = dirty->fb_y + vclips_ptr->h +
  2072. dest_y - crtc_y;
  2073. }
  2074. dirty->unit_x1 = dirty->fb_x + dest_x - crtc_x;
  2075. dirty->unit_y1 = dirty->fb_y + dest_y - crtc_y;
  2076. /* Skip this clip if it's outside the crtc region */
  2077. if (dirty->unit_x1 >= crtc_width ||
  2078. dirty->unit_y1 >= crtc_height ||
  2079. dirty->unit_x2 <= 0 || dirty->unit_y2 <= 0)
  2080. continue;
  2081. /* Clip right and bottom to crtc limits */
  2082. dirty->unit_x2 = min_t(s32, dirty->unit_x2,
  2083. crtc_width);
  2084. dirty->unit_y2 = min_t(s32, dirty->unit_y2,
  2085. crtc_height);
  2086. /* Clip left and top to crtc limits */
  2087. clip_left = min_t(s32, dirty->unit_x1, 0);
  2088. clip_top = min_t(s32, dirty->unit_y1, 0);
  2089. dirty->unit_x1 -= clip_left;
  2090. dirty->unit_y1 -= clip_top;
  2091. dirty->fb_x -= clip_left;
  2092. dirty->fb_y -= clip_top;
  2093. dirty->clip(dirty);
  2094. }
  2095. dirty->fifo_commit(dirty);
  2096. }
  2097. return 0;
  2098. }
  2099. /**
  2100. * vmw_kms_helper_buffer_prepare - Reserve and validate a buffer object before
  2101. * command submission.
  2102. *
  2103. * @dev_priv. Pointer to a device private structure.
  2104. * @buf: The buffer object
  2105. * @interruptible: Whether to perform waits as interruptible.
  2106. * @validate_as_mob: Whether the buffer should be validated as a MOB. If false,
  2107. * The buffer will be validated as a GMR. Already pinned buffers will not be
  2108. * validated.
  2109. *
  2110. * Returns 0 on success, negative error code on failure, -ERESTARTSYS if
  2111. * interrupted by a signal.
  2112. */
  2113. int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv,
  2114. struct vmw_dma_buffer *buf,
  2115. bool interruptible,
  2116. bool validate_as_mob)
  2117. {
  2118. struct ttm_buffer_object *bo = &buf->base;
  2119. int ret;
  2120. ttm_bo_reserve(bo, false, false, NULL);
  2121. ret = vmw_validate_single_buffer(dev_priv, bo, interruptible,
  2122. validate_as_mob);
  2123. if (ret)
  2124. ttm_bo_unreserve(bo);
  2125. return ret;
  2126. }
  2127. /**
  2128. * vmw_kms_helper_buffer_revert - Undo the actions of
  2129. * vmw_kms_helper_buffer_prepare.
  2130. *
  2131. * @res: Pointer to the buffer object.
  2132. *
  2133. * Helper to be used if an error forces the caller to undo the actions of
  2134. * vmw_kms_helper_buffer_prepare.
  2135. */
  2136. void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer *buf)
  2137. {
  2138. if (buf)
  2139. ttm_bo_unreserve(&buf->base);
  2140. }
  2141. /**
  2142. * vmw_kms_helper_buffer_finish - Unreserve and fence a buffer object after
  2143. * kms command submission.
  2144. *
  2145. * @dev_priv: Pointer to a device private structure.
  2146. * @file_priv: Pointer to a struct drm_file representing the caller's
  2147. * connection. Must be set to NULL if @user_fence_rep is NULL, and conversely
  2148. * if non-NULL, @user_fence_rep must be non-NULL.
  2149. * @buf: The buffer object.
  2150. * @out_fence: Optional pointer to a fence pointer. If non-NULL, a
  2151. * ref-counted fence pointer is returned here.
  2152. * @user_fence_rep: Optional pointer to a user-space provided struct
  2153. * drm_vmw_fence_rep. If provided, @file_priv must also be provided and the
  2154. * function copies fence data to user-space in a fail-safe manner.
  2155. */
  2156. void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv,
  2157. struct drm_file *file_priv,
  2158. struct vmw_dma_buffer *buf,
  2159. struct vmw_fence_obj **out_fence,
  2160. struct drm_vmw_fence_rep __user *
  2161. user_fence_rep)
  2162. {
  2163. struct vmw_fence_obj *fence;
  2164. uint32_t handle;
  2165. int ret;
  2166. ret = vmw_execbuf_fence_commands(file_priv, dev_priv, &fence,
  2167. file_priv ? &handle : NULL);
  2168. if (buf)
  2169. vmw_fence_single_bo(&buf->base, fence);
  2170. if (file_priv)
  2171. vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv),
  2172. ret, user_fence_rep, fence,
  2173. handle);
  2174. if (out_fence)
  2175. *out_fence = fence;
  2176. else
  2177. vmw_fence_obj_unreference(&fence);
  2178. vmw_kms_helper_buffer_revert(buf);
  2179. }
  2180. /**
  2181. * vmw_kms_helper_resource_revert - Undo the actions of
  2182. * vmw_kms_helper_resource_prepare.
  2183. *
  2184. * @res: Pointer to the resource. Typically a surface.
  2185. *
  2186. * Helper to be used if an error forces the caller to undo the actions of
  2187. * vmw_kms_helper_resource_prepare.
  2188. */
  2189. void vmw_kms_helper_resource_revert(struct vmw_resource *res)
  2190. {
  2191. vmw_kms_helper_buffer_revert(res->backup);
  2192. vmw_resource_unreserve(res, false, NULL, 0);
  2193. mutex_unlock(&res->dev_priv->cmdbuf_mutex);
  2194. }
  2195. /**
  2196. * vmw_kms_helper_resource_prepare - Reserve and validate a resource before
  2197. * command submission.
  2198. *
  2199. * @res: Pointer to the resource. Typically a surface.
  2200. * @interruptible: Whether to perform waits as interruptible.
  2201. *
  2202. * Reserves and validates also the backup buffer if a guest-backed resource.
  2203. * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
  2204. * interrupted by a signal.
  2205. */
  2206. int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
  2207. bool interruptible)
  2208. {
  2209. int ret = 0;
  2210. if (interruptible)
  2211. ret = mutex_lock_interruptible(&res->dev_priv->cmdbuf_mutex);
  2212. else
  2213. mutex_lock(&res->dev_priv->cmdbuf_mutex);
  2214. if (unlikely(ret != 0))
  2215. return -ERESTARTSYS;
  2216. ret = vmw_resource_reserve(res, interruptible, false);
  2217. if (ret)
  2218. goto out_unlock;
  2219. if (res->backup) {
  2220. ret = vmw_kms_helper_buffer_prepare(res->dev_priv, res->backup,
  2221. interruptible,
  2222. res->dev_priv->has_mob);
  2223. if (ret)
  2224. goto out_unreserve;
  2225. }
  2226. ret = vmw_resource_validate(res);
  2227. if (ret)
  2228. goto out_revert;
  2229. return 0;
  2230. out_revert:
  2231. vmw_kms_helper_buffer_revert(res->backup);
  2232. out_unreserve:
  2233. vmw_resource_unreserve(res, false, NULL, 0);
  2234. out_unlock:
  2235. mutex_unlock(&res->dev_priv->cmdbuf_mutex);
  2236. return ret;
  2237. }
  2238. /**
  2239. * vmw_kms_helper_resource_finish - Unreserve and fence a resource after
  2240. * kms command submission.
  2241. *
  2242. * @res: Pointer to the resource. Typically a surface.
  2243. * @out_fence: Optional pointer to a fence pointer. If non-NULL, a
  2244. * ref-counted fence pointer is returned here.
  2245. */
  2246. void vmw_kms_helper_resource_finish(struct vmw_resource *res,
  2247. struct vmw_fence_obj **out_fence)
  2248. {
  2249. if (res->backup || out_fence)
  2250. vmw_kms_helper_buffer_finish(res->dev_priv, NULL, res->backup,
  2251. out_fence, NULL);
  2252. vmw_resource_unreserve(res, false, NULL, 0);
  2253. mutex_unlock(&res->dev_priv->cmdbuf_mutex);
  2254. }
  2255. /**
  2256. * vmw_kms_update_proxy - Helper function to update a proxy surface from
  2257. * its backing MOB.
  2258. *
  2259. * @res: Pointer to the surface resource
  2260. * @clips: Clip rects in framebuffer (surface) space.
  2261. * @num_clips: Number of clips in @clips.
  2262. * @increment: Integer with which to increment the clip counter when looping.
  2263. * Used to skip a predetermined number of clip rects.
  2264. *
  2265. * This function makes sure the proxy surface is updated from its backing MOB
  2266. * using the region given by @clips. The surface resource @res and its backing
  2267. * MOB needs to be reserved and validated on call.
  2268. */
  2269. int vmw_kms_update_proxy(struct vmw_resource *res,
  2270. const struct drm_clip_rect *clips,
  2271. unsigned num_clips,
  2272. int increment)
  2273. {
  2274. struct vmw_private *dev_priv = res->dev_priv;
  2275. struct drm_vmw_size *size = &vmw_res_to_srf(res)->base_size;
  2276. struct {
  2277. SVGA3dCmdHeader header;
  2278. SVGA3dCmdUpdateGBImage body;
  2279. } *cmd;
  2280. SVGA3dBox *box;
  2281. size_t copy_size = 0;
  2282. int i;
  2283. if (!clips)
  2284. return 0;
  2285. cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd) * num_clips);
  2286. if (!cmd) {
  2287. DRM_ERROR("Couldn't reserve fifo space for proxy surface "
  2288. "update.\n");
  2289. return -ENOMEM;
  2290. }
  2291. for (i = 0; i < num_clips; ++i, clips += increment, ++cmd) {
  2292. box = &cmd->body.box;
  2293. cmd->header.id = SVGA_3D_CMD_UPDATE_GB_IMAGE;
  2294. cmd->header.size = sizeof(cmd->body);
  2295. cmd->body.image.sid = res->id;
  2296. cmd->body.image.face = 0;
  2297. cmd->body.image.mipmap = 0;
  2298. if (clips->x1 > size->width || clips->x2 > size->width ||
  2299. clips->y1 > size->height || clips->y2 > size->height) {
  2300. DRM_ERROR("Invalid clips outsize of framebuffer.\n");
  2301. return -EINVAL;
  2302. }
  2303. box->x = clips->x1;
  2304. box->y = clips->y1;
  2305. box->z = 0;
  2306. box->w = clips->x2 - clips->x1;
  2307. box->h = clips->y2 - clips->y1;
  2308. box->d = 1;
  2309. copy_size += sizeof(*cmd);
  2310. }
  2311. vmw_fifo_commit(dev_priv, copy_size);
  2312. return 0;
  2313. }
  2314. int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv,
  2315. unsigned unit,
  2316. u32 max_width,
  2317. u32 max_height,
  2318. struct drm_connector **p_con,
  2319. struct drm_crtc **p_crtc,
  2320. struct drm_display_mode **p_mode)
  2321. {
  2322. struct drm_connector *con;
  2323. struct vmw_display_unit *du;
  2324. struct drm_display_mode *mode;
  2325. int i = 0;
  2326. list_for_each_entry(con, &dev_priv->dev->mode_config.connector_list,
  2327. head) {
  2328. if (i == unit)
  2329. break;
  2330. ++i;
  2331. }
  2332. if (i != unit) {
  2333. DRM_ERROR("Could not find initial display unit.\n");
  2334. return -EINVAL;
  2335. }
  2336. if (list_empty(&con->modes))
  2337. (void) vmw_du_connector_fill_modes(con, max_width, max_height);
  2338. if (list_empty(&con->modes)) {
  2339. DRM_ERROR("Could not find initial display mode.\n");
  2340. return -EINVAL;
  2341. }
  2342. du = vmw_connector_to_du(con);
  2343. *p_con = con;
  2344. *p_crtc = &du->crtc;
  2345. list_for_each_entry(mode, &con->modes, head) {
  2346. if (mode->type & DRM_MODE_TYPE_PREFERRED)
  2347. break;
  2348. }
  2349. if (mode->type & DRM_MODE_TYPE_PREFERRED)
  2350. *p_mode = mode;
  2351. else {
  2352. WARN_ONCE(true, "Could not find initial preferred mode.\n");
  2353. *p_mode = list_first_entry(&con->modes,
  2354. struct drm_display_mode,
  2355. head);
  2356. }
  2357. return 0;
  2358. }
  2359. /**
  2360. * vmw_kms_del_active - unregister a crtc binding to the implicit framebuffer
  2361. *
  2362. * @dev_priv: Pointer to a device private struct.
  2363. * @du: The display unit of the crtc.
  2364. */
  2365. void vmw_kms_del_active(struct vmw_private *dev_priv,
  2366. struct vmw_display_unit *du)
  2367. {
  2368. mutex_lock(&dev_priv->global_kms_state_mutex);
  2369. if (du->active_implicit) {
  2370. if (--(dev_priv->num_implicit) == 0)
  2371. dev_priv->implicit_fb = NULL;
  2372. du->active_implicit = false;
  2373. }
  2374. mutex_unlock(&dev_priv->global_kms_state_mutex);
  2375. }
  2376. /**
  2377. * vmw_kms_add_active - register a crtc binding to an implicit framebuffer
  2378. *
  2379. * @vmw_priv: Pointer to a device private struct.
  2380. * @du: The display unit of the crtc.
  2381. * @vfb: The implicit framebuffer
  2382. *
  2383. * Registers a binding to an implicit framebuffer.
  2384. */
  2385. void vmw_kms_add_active(struct vmw_private *dev_priv,
  2386. struct vmw_display_unit *du,
  2387. struct vmw_framebuffer *vfb)
  2388. {
  2389. mutex_lock(&dev_priv->global_kms_state_mutex);
  2390. WARN_ON_ONCE(!dev_priv->num_implicit && dev_priv->implicit_fb);
  2391. if (!du->active_implicit && du->is_implicit) {
  2392. dev_priv->implicit_fb = vfb;
  2393. du->active_implicit = true;
  2394. dev_priv->num_implicit++;
  2395. }
  2396. mutex_unlock(&dev_priv->global_kms_state_mutex);
  2397. }
  2398. /**
  2399. * vmw_kms_screen_object_flippable - Check whether we can page-flip a crtc.
  2400. *
  2401. * @dev_priv: Pointer to device-private struct.
  2402. * @crtc: The crtc we want to flip.
  2403. *
  2404. * Returns true or false depending whether it's OK to flip this crtc
  2405. * based on the criterion that we must not have more than one implicit
  2406. * frame-buffer at any one time.
  2407. */
  2408. bool vmw_kms_crtc_flippable(struct vmw_private *dev_priv,
  2409. struct drm_crtc *crtc)
  2410. {
  2411. struct vmw_display_unit *du = vmw_crtc_to_du(crtc);
  2412. bool ret;
  2413. mutex_lock(&dev_priv->global_kms_state_mutex);
  2414. ret = !du->is_implicit || dev_priv->num_implicit == 1;
  2415. mutex_unlock(&dev_priv->global_kms_state_mutex);
  2416. return ret;
  2417. }
  2418. /**
  2419. * vmw_kms_update_implicit_fb - Update the implicit fb.
  2420. *
  2421. * @dev_priv: Pointer to device-private struct.
  2422. * @crtc: The crtc the new implicit frame-buffer is bound to.
  2423. */
  2424. void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv,
  2425. struct drm_crtc *crtc)
  2426. {
  2427. struct vmw_display_unit *du = vmw_crtc_to_du(crtc);
  2428. struct vmw_framebuffer *vfb;
  2429. mutex_lock(&dev_priv->global_kms_state_mutex);
  2430. if (!du->is_implicit)
  2431. goto out_unlock;
  2432. vfb = vmw_framebuffer_to_vfb(crtc->primary->fb);
  2433. WARN_ON_ONCE(dev_priv->num_implicit != 1 &&
  2434. dev_priv->implicit_fb != vfb);
  2435. dev_priv->implicit_fb = vfb;
  2436. out_unlock:
  2437. mutex_unlock(&dev_priv->global_kms_state_mutex);
  2438. }
  2439. /**
  2440. * vmw_kms_create_implicit_placement_proparty - Set up the implicit placement
  2441. * property.
  2442. *
  2443. * @dev_priv: Pointer to a device private struct.
  2444. * @immutable: Whether the property is immutable.
  2445. *
  2446. * Sets up the implicit placement property unless it's already set up.
  2447. */
  2448. void
  2449. vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv,
  2450. bool immutable)
  2451. {
  2452. if (dev_priv->implicit_placement_property)
  2453. return;
  2454. dev_priv->implicit_placement_property =
  2455. drm_property_create_range(dev_priv->dev,
  2456. immutable ?
  2457. DRM_MODE_PROP_IMMUTABLE : 0,
  2458. "implicit_placement", 0, 1);
  2459. }
  2460. /**
  2461. * vmw_kms_set_config - Wrapper around drm_atomic_helper_set_config
  2462. *
  2463. * @set: The configuration to set.
  2464. *
  2465. * The vmwgfx Xorg driver doesn't assign the mode::type member, which
  2466. * when drm_mode_set_crtcinfo is called as part of the configuration setting
  2467. * causes it to return incorrect crtc dimensions causing severe problems in
  2468. * the vmwgfx modesetting. So explicitly clear that member before calling
  2469. * into drm_atomic_helper_set_config.
  2470. */
  2471. int vmw_kms_set_config(struct drm_mode_set *set,
  2472. struct drm_modeset_acquire_ctx *ctx)
  2473. {
  2474. if (set && set->mode)
  2475. set->mode->type = 0;
  2476. return drm_atomic_helper_set_config(set, ctx);
  2477. }