vmwgfx_kms.c 77 KB

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