drm_gpuvm.h 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  1. /* SPDX-License-Identifier: GPL-2.0-only OR MIT */
  2. #ifndef __DRM_GPUVM_H__
  3. #define __DRM_GPUVM_H__
  4. /*
  5. * Copyright (c) 2022 Red Hat.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  21. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  22. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. * OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #include <linux/dma-resv.h>
  26. #include <linux/list.h>
  27. #include <linux/rbtree.h>
  28. #include <linux/types.h>
  29. #include <drm/drm_device.h>
  30. #include <drm/drm_gem.h>
  31. #include <drm/drm_exec.h>
  32. struct drm_gpuvm;
  33. struct drm_gpuvm_bo;
  34. struct drm_gpuvm_ops;
  35. /**
  36. * enum drm_gpuva_flags - flags for struct drm_gpuva
  37. */
  38. enum drm_gpuva_flags {
  39. /**
  40. * @DRM_GPUVA_INVALIDATED:
  41. *
  42. * Flag indicating that the &drm_gpuva's backing GEM is invalidated.
  43. */
  44. DRM_GPUVA_INVALIDATED = (1 << 0),
  45. /**
  46. * @DRM_GPUVA_SPARSE:
  47. *
  48. * Flag indicating that the &drm_gpuva is a sparse mapping.
  49. */
  50. DRM_GPUVA_SPARSE = (1 << 1),
  51. /**
  52. * @DRM_GPUVA_USERBITS: user defined bits
  53. */
  54. DRM_GPUVA_USERBITS = (1 << 2),
  55. };
  56. /**
  57. * struct drm_gpuva - structure to track a GPU VA mapping
  58. *
  59. * This structure represents a GPU VA mapping and is associated with a
  60. * &drm_gpuvm.
  61. *
  62. * Typically, this structure is embedded in bigger driver structures.
  63. */
  64. struct drm_gpuva {
  65. /**
  66. * @vm: the &drm_gpuvm this object is associated with
  67. */
  68. struct drm_gpuvm *vm;
  69. /**
  70. * @vm_bo: the &drm_gpuvm_bo abstraction for the mapped
  71. * &drm_gem_object
  72. */
  73. struct drm_gpuvm_bo *vm_bo;
  74. /**
  75. * @flags: the &drm_gpuva_flags for this mapping
  76. */
  77. enum drm_gpuva_flags flags;
  78. /**
  79. * @va: structure containing the address and range of the &drm_gpuva
  80. */
  81. struct {
  82. /**
  83. * @va.addr: the start address
  84. */
  85. u64 addr;
  86. /*
  87. * @range: the range
  88. */
  89. u64 range;
  90. } va;
  91. /**
  92. * @gem: structure containing the &drm_gem_object and it's offset
  93. */
  94. struct {
  95. /**
  96. * @gem.offset: the offset within the &drm_gem_object
  97. */
  98. u64 offset;
  99. /**
  100. * @gem.obj: the mapped &drm_gem_object
  101. */
  102. struct drm_gem_object *obj;
  103. /**
  104. * @gem.entry: the &list_head to attach this object to a &drm_gpuvm_bo
  105. */
  106. struct list_head entry;
  107. } gem;
  108. /**
  109. * @rb: structure containing data to store &drm_gpuvas in a rb-tree
  110. */
  111. struct {
  112. /**
  113. * @rb.node: the rb-tree node
  114. */
  115. struct rb_node node;
  116. /**
  117. * @rb.entry: The &list_head to additionally connect &drm_gpuvas
  118. * in the same order they appear in the interval tree. This is
  119. * useful to keep iterating &drm_gpuvas from a start node found
  120. * through the rb-tree while doing modifications on the rb-tree
  121. * itself.
  122. */
  123. struct list_head entry;
  124. /**
  125. * @rb.__subtree_last: needed by the interval tree, holding last-in-subtree
  126. */
  127. u64 __subtree_last;
  128. } rb;
  129. };
  130. int drm_gpuva_insert(struct drm_gpuvm *gpuvm, struct drm_gpuva *va);
  131. void drm_gpuva_remove(struct drm_gpuva *va);
  132. void drm_gpuva_link(struct drm_gpuva *va, struct drm_gpuvm_bo *vm_bo);
  133. void drm_gpuva_unlink(struct drm_gpuva *va);
  134. struct drm_gpuva *drm_gpuva_find(struct drm_gpuvm *gpuvm,
  135. u64 addr, u64 range);
  136. struct drm_gpuva *drm_gpuva_find_first(struct drm_gpuvm *gpuvm,
  137. u64 addr, u64 range);
  138. struct drm_gpuva *drm_gpuva_find_prev(struct drm_gpuvm *gpuvm, u64 start);
  139. struct drm_gpuva *drm_gpuva_find_next(struct drm_gpuvm *gpuvm, u64 end);
  140. static inline void drm_gpuva_init(struct drm_gpuva *va, u64 addr, u64 range,
  141. struct drm_gem_object *obj, u64 offset)
  142. {
  143. va->va.addr = addr;
  144. va->va.range = range;
  145. va->gem.obj = obj;
  146. va->gem.offset = offset;
  147. }
  148. /**
  149. * drm_gpuva_invalidate() - sets whether the backing GEM of this &drm_gpuva is
  150. * invalidated
  151. * @va: the &drm_gpuva to set the invalidate flag for
  152. * @invalidate: indicates whether the &drm_gpuva is invalidated
  153. */
  154. static inline void drm_gpuva_invalidate(struct drm_gpuva *va, bool invalidate)
  155. {
  156. if (invalidate)
  157. va->flags |= DRM_GPUVA_INVALIDATED;
  158. else
  159. va->flags &= ~DRM_GPUVA_INVALIDATED;
  160. }
  161. /**
  162. * drm_gpuva_invalidated() - indicates whether the backing BO of this &drm_gpuva
  163. * is invalidated
  164. * @va: the &drm_gpuva to check
  165. *
  166. * Returns: %true if the GPU VA is invalidated, %false otherwise
  167. */
  168. static inline bool drm_gpuva_invalidated(struct drm_gpuva *va)
  169. {
  170. return va->flags & DRM_GPUVA_INVALIDATED;
  171. }
  172. /**
  173. * enum drm_gpuvm_flags - flags for struct drm_gpuvm
  174. */
  175. enum drm_gpuvm_flags {
  176. /**
  177. * @DRM_GPUVM_RESV_PROTECTED: GPUVM is protected externally by the
  178. * GPUVM's &dma_resv lock
  179. */
  180. DRM_GPUVM_RESV_PROTECTED = BIT(0),
  181. /**
  182. * @DRM_GPUVM_USERBITS: user defined bits
  183. */
  184. DRM_GPUVM_USERBITS = BIT(1),
  185. };
  186. /**
  187. * struct drm_gpuvm - DRM GPU VA Manager
  188. *
  189. * The DRM GPU VA Manager keeps track of a GPU's virtual address space by using
  190. * &maple_tree structures. Typically, this structure is embedded in bigger
  191. * driver structures.
  192. *
  193. * Drivers can pass addresses and ranges in an arbitrary unit, e.g. bytes or
  194. * pages.
  195. *
  196. * There should be one manager instance per GPU virtual address space.
  197. */
  198. struct drm_gpuvm {
  199. /**
  200. * @name: the name of the DRM GPU VA space
  201. */
  202. const char *name;
  203. /**
  204. * @flags: the &drm_gpuvm_flags of this GPUVM
  205. */
  206. enum drm_gpuvm_flags flags;
  207. /**
  208. * @drm: the &drm_device this VM lives in
  209. */
  210. struct drm_device *drm;
  211. /**
  212. * @mm_start: start of the VA space
  213. */
  214. u64 mm_start;
  215. /**
  216. * @mm_range: length of the VA space
  217. */
  218. u64 mm_range;
  219. /**
  220. * @rb: structures to track &drm_gpuva entries
  221. */
  222. struct {
  223. /**
  224. * @rb.tree: the rb-tree to track GPU VA mappings
  225. */
  226. struct rb_root_cached tree;
  227. /**
  228. * @rb.list: the &list_head to track GPU VA mappings
  229. */
  230. struct list_head list;
  231. } rb;
  232. /**
  233. * @kref: reference count of this object
  234. */
  235. struct kref kref;
  236. /**
  237. * @kernel_alloc_node:
  238. *
  239. * &drm_gpuva representing the address space cutout reserved for
  240. * the kernel
  241. */
  242. struct drm_gpuva kernel_alloc_node;
  243. /**
  244. * @ops: &drm_gpuvm_ops providing the split/merge steps to drivers
  245. */
  246. const struct drm_gpuvm_ops *ops;
  247. /**
  248. * @r_obj: Resv GEM object; representing the GPUVM's common &dma_resv.
  249. */
  250. struct drm_gem_object *r_obj;
  251. /**
  252. * @extobj: structure holding the extobj list
  253. */
  254. struct {
  255. /**
  256. * @extobj.list: &list_head storing &drm_gpuvm_bos serving as
  257. * external object
  258. */
  259. struct list_head list;
  260. /**
  261. * @extobj.local_list: pointer to the local list temporarily
  262. * storing entries from the external object list
  263. */
  264. struct list_head *local_list;
  265. /**
  266. * @extobj.lock: spinlock to protect the extobj list
  267. */
  268. spinlock_t lock;
  269. } extobj;
  270. /**
  271. * @evict: structure holding the evict list and evict list lock
  272. */
  273. struct {
  274. /**
  275. * @evict.list: &list_head storing &drm_gpuvm_bos currently
  276. * being evicted
  277. */
  278. struct list_head list;
  279. /**
  280. * @evict.local_list: pointer to the local list temporarily
  281. * storing entries from the evicted object list
  282. */
  283. struct list_head *local_list;
  284. /**
  285. * @evict.lock: spinlock to protect the evict list
  286. */
  287. spinlock_t lock;
  288. } evict;
  289. };
  290. void drm_gpuvm_init(struct drm_gpuvm *gpuvm, const char *name,
  291. enum drm_gpuvm_flags flags,
  292. struct drm_device *drm,
  293. struct drm_gem_object *r_obj,
  294. u64 start_offset, u64 range,
  295. u64 reserve_offset, u64 reserve_range,
  296. const struct drm_gpuvm_ops *ops);
  297. /**
  298. * drm_gpuvm_get() - acquire a struct drm_gpuvm reference
  299. * @gpuvm: the &drm_gpuvm to acquire the reference of
  300. *
  301. * This function acquires an additional reference to @gpuvm. It is illegal to
  302. * call this without already holding a reference. No locks required.
  303. *
  304. * Returns: the &struct drm_gpuvm pointer
  305. */
  306. static inline struct drm_gpuvm *
  307. drm_gpuvm_get(struct drm_gpuvm *gpuvm)
  308. {
  309. kref_get(&gpuvm->kref);
  310. return gpuvm;
  311. }
  312. void drm_gpuvm_put(struct drm_gpuvm *gpuvm);
  313. bool drm_gpuvm_range_valid(struct drm_gpuvm *gpuvm, u64 addr, u64 range);
  314. bool drm_gpuvm_interval_empty(struct drm_gpuvm *gpuvm, u64 addr, u64 range);
  315. struct drm_gem_object *
  316. drm_gpuvm_resv_object_alloc(struct drm_device *drm);
  317. /**
  318. * drm_gpuvm_resv_protected() - indicates whether &DRM_GPUVM_RESV_PROTECTED is
  319. * set
  320. * @gpuvm: the &drm_gpuvm
  321. *
  322. * Returns: true if &DRM_GPUVM_RESV_PROTECTED is set, false otherwise.
  323. */
  324. static inline bool
  325. drm_gpuvm_resv_protected(struct drm_gpuvm *gpuvm)
  326. {
  327. return gpuvm->flags & DRM_GPUVM_RESV_PROTECTED;
  328. }
  329. /**
  330. * drm_gpuvm_resv() - returns the &drm_gpuvm's &dma_resv
  331. * @gpuvm__: the &drm_gpuvm
  332. *
  333. * Returns: a pointer to the &drm_gpuvm's shared &dma_resv
  334. */
  335. #define drm_gpuvm_resv(gpuvm__) ((gpuvm__)->r_obj->resv)
  336. /**
  337. * drm_gpuvm_resv_obj() - returns the &drm_gem_object holding the &drm_gpuvm's
  338. * &dma_resv
  339. * @gpuvm__: the &drm_gpuvm
  340. *
  341. * Returns: a pointer to the &drm_gem_object holding the &drm_gpuvm's shared
  342. * &dma_resv
  343. */
  344. #define drm_gpuvm_resv_obj(gpuvm__) ((gpuvm__)->r_obj)
  345. #define drm_gpuvm_resv_held(gpuvm__) \
  346. dma_resv_held(drm_gpuvm_resv(gpuvm__))
  347. #define drm_gpuvm_resv_assert_held(gpuvm__) \
  348. dma_resv_assert_held(drm_gpuvm_resv(gpuvm__))
  349. #define drm_gpuvm_resv_held(gpuvm__) \
  350. dma_resv_held(drm_gpuvm_resv(gpuvm__))
  351. #define drm_gpuvm_resv_assert_held(gpuvm__) \
  352. dma_resv_assert_held(drm_gpuvm_resv(gpuvm__))
  353. /**
  354. * drm_gpuvm_is_extobj() - indicates whether the given &drm_gem_object is an
  355. * external object
  356. * @gpuvm: the &drm_gpuvm to check
  357. * @obj: the &drm_gem_object to check
  358. *
  359. * Returns: true if the &drm_gem_object &dma_resv differs from the
  360. * &drm_gpuvms &dma_resv, false otherwise
  361. */
  362. static inline bool
  363. drm_gpuvm_is_extobj(struct drm_gpuvm *gpuvm,
  364. struct drm_gem_object *obj)
  365. {
  366. return obj && obj->resv != drm_gpuvm_resv(gpuvm);
  367. }
  368. static inline struct drm_gpuva *
  369. __drm_gpuva_next(struct drm_gpuva *va)
  370. {
  371. if (va && !list_is_last(&va->rb.entry, &va->vm->rb.list))
  372. return list_next_entry(va, rb.entry);
  373. return NULL;
  374. }
  375. /**
  376. * drm_gpuvm_for_each_va_range() - iterate over a range of &drm_gpuvas
  377. * @va__: &drm_gpuva structure to assign to in each iteration step
  378. * @gpuvm__: &drm_gpuvm to walk over
  379. * @start__: starting offset, the first gpuva will overlap this
  380. * @end__: ending offset, the last gpuva will start before this (but may
  381. * overlap)
  382. *
  383. * This iterator walks over all &drm_gpuvas in the &drm_gpuvm that lie
  384. * between @start__ and @end__. It is implemented similarly to list_for_each(),
  385. * but is using the &drm_gpuvm's internal interval tree to accelerate
  386. * the search for the starting &drm_gpuva, and hence isn't safe against removal
  387. * of elements. It assumes that @end__ is within (or is the upper limit of) the
  388. * &drm_gpuvm. This iterator does not skip over the &drm_gpuvm's
  389. * @kernel_alloc_node.
  390. */
  391. #define drm_gpuvm_for_each_va_range(va__, gpuvm__, start__, end__) \
  392. for (va__ = drm_gpuva_find_first((gpuvm__), (start__), (end__) - (start__)); \
  393. va__ && (va__->va.addr < (end__)); \
  394. va__ = __drm_gpuva_next(va__))
  395. /**
  396. * drm_gpuvm_for_each_va_range_safe() - safely iterate over a range of
  397. * &drm_gpuvas
  398. * @va__: &drm_gpuva to assign to in each iteration step
  399. * @next__: another &drm_gpuva to use as temporary storage
  400. * @gpuvm__: &drm_gpuvm to walk over
  401. * @start__: starting offset, the first gpuva will overlap this
  402. * @end__: ending offset, the last gpuva will start before this (but may
  403. * overlap)
  404. *
  405. * This iterator walks over all &drm_gpuvas in the &drm_gpuvm that lie
  406. * between @start__ and @end__. It is implemented similarly to
  407. * list_for_each_safe(), but is using the &drm_gpuvm's internal interval
  408. * tree to accelerate the search for the starting &drm_gpuva, and hence is safe
  409. * against removal of elements. It assumes that @end__ is within (or is the
  410. * upper limit of) the &drm_gpuvm. This iterator does not skip over the
  411. * &drm_gpuvm's @kernel_alloc_node.
  412. */
  413. #define drm_gpuvm_for_each_va_range_safe(va__, next__, gpuvm__, start__, end__) \
  414. for (va__ = drm_gpuva_find_first((gpuvm__), (start__), (end__) - (start__)), \
  415. next__ = __drm_gpuva_next(va__); \
  416. va__ && (va__->va.addr < (end__)); \
  417. va__ = next__, next__ = __drm_gpuva_next(va__))
  418. /**
  419. * drm_gpuvm_for_each_va() - iterate over all &drm_gpuvas
  420. * @va__: &drm_gpuva to assign to in each iteration step
  421. * @gpuvm__: &drm_gpuvm to walk over
  422. *
  423. * This iterator walks over all &drm_gpuva structures associated with the given
  424. * &drm_gpuvm.
  425. */
  426. #define drm_gpuvm_for_each_va(va__, gpuvm__) \
  427. list_for_each_entry(va__, &(gpuvm__)->rb.list, rb.entry)
  428. /**
  429. * drm_gpuvm_for_each_va_safe() - safely iterate over all &drm_gpuvas
  430. * @va__: &drm_gpuva to assign to in each iteration step
  431. * @next__: another &drm_gpuva to use as temporary storage
  432. * @gpuvm__: &drm_gpuvm to walk over
  433. *
  434. * This iterator walks over all &drm_gpuva structures associated with the given
  435. * &drm_gpuvm. It is implemented with list_for_each_entry_safe(), and
  436. * hence safe against the removal of elements.
  437. */
  438. #define drm_gpuvm_for_each_va_safe(va__, next__, gpuvm__) \
  439. list_for_each_entry_safe(va__, next__, &(gpuvm__)->rb.list, rb.entry)
  440. /**
  441. * struct drm_gpuvm_exec - &drm_gpuvm abstraction of &drm_exec
  442. *
  443. * This structure should be created on the stack as &drm_exec should be.
  444. *
  445. * Optionally, @extra can be set in order to lock additional &drm_gem_objects.
  446. */
  447. struct drm_gpuvm_exec {
  448. /**
  449. * @exec: the &drm_exec structure
  450. */
  451. struct drm_exec exec;
  452. /**
  453. * @flags: the flags for the struct drm_exec
  454. */
  455. u32 flags;
  456. /**
  457. * @vm: the &drm_gpuvm to lock its DMA reservations
  458. */
  459. struct drm_gpuvm *vm;
  460. /**
  461. * @num_fences: the number of fences to reserve for the &dma_resv of the
  462. * locked &drm_gem_objects
  463. */
  464. unsigned int num_fences;
  465. /**
  466. * @extra: Callback and corresponding private data for the driver to
  467. * lock arbitrary additional &drm_gem_objects.
  468. */
  469. struct {
  470. /**
  471. * @extra.fn: The driver callback to lock additional
  472. * &drm_gem_objects.
  473. */
  474. int (*fn)(struct drm_gpuvm_exec *vm_exec);
  475. /**
  476. * @extra.priv: driver private data for the @fn callback
  477. */
  478. void *priv;
  479. } extra;
  480. };
  481. int drm_gpuvm_prepare_vm(struct drm_gpuvm *gpuvm,
  482. struct drm_exec *exec,
  483. unsigned int num_fences);
  484. int drm_gpuvm_prepare_objects(struct drm_gpuvm *gpuvm,
  485. struct drm_exec *exec,
  486. unsigned int num_fences);
  487. int drm_gpuvm_prepare_range(struct drm_gpuvm *gpuvm,
  488. struct drm_exec *exec,
  489. u64 addr, u64 range,
  490. unsigned int num_fences);
  491. int drm_gpuvm_exec_lock(struct drm_gpuvm_exec *vm_exec);
  492. int drm_gpuvm_exec_lock_array(struct drm_gpuvm_exec *vm_exec,
  493. struct drm_gem_object **objs,
  494. unsigned int num_objs);
  495. int drm_gpuvm_exec_lock_range(struct drm_gpuvm_exec *vm_exec,
  496. u64 addr, u64 range);
  497. /**
  498. * drm_gpuvm_exec_unlock() - lock all dma-resv of all assoiciated BOs
  499. * @vm_exec: the &drm_gpuvm_exec wrapper
  500. *
  501. * Releases all dma-resv locks of all &drm_gem_objects previously acquired
  502. * through drm_gpuvm_exec_lock() or its variants.
  503. *
  504. * Returns: 0 on success, negative error code on failure.
  505. */
  506. static inline void
  507. drm_gpuvm_exec_unlock(struct drm_gpuvm_exec *vm_exec)
  508. {
  509. drm_exec_fini(&vm_exec->exec);
  510. }
  511. int drm_gpuvm_validate(struct drm_gpuvm *gpuvm, struct drm_exec *exec);
  512. void drm_gpuvm_resv_add_fence(struct drm_gpuvm *gpuvm,
  513. struct drm_exec *exec,
  514. struct dma_fence *fence,
  515. enum dma_resv_usage private_usage,
  516. enum dma_resv_usage extobj_usage);
  517. /**
  518. * drm_gpuvm_exec_resv_add_fence() - add fence to private and all extobj
  519. * @vm_exec: the &drm_gpuvm_exec wrapper
  520. * @fence: fence to add
  521. * @private_usage: private dma-resv usage
  522. * @extobj_usage: extobj dma-resv usage
  523. *
  524. * See drm_gpuvm_resv_add_fence().
  525. */
  526. static inline void
  527. drm_gpuvm_exec_resv_add_fence(struct drm_gpuvm_exec *vm_exec,
  528. struct dma_fence *fence,
  529. enum dma_resv_usage private_usage,
  530. enum dma_resv_usage extobj_usage)
  531. {
  532. drm_gpuvm_resv_add_fence(vm_exec->vm, &vm_exec->exec, fence,
  533. private_usage, extobj_usage);
  534. }
  535. /**
  536. * drm_gpuvm_exec_validate() - validate all BOs marked as evicted
  537. * @vm_exec: the &drm_gpuvm_exec wrapper
  538. *
  539. * See drm_gpuvm_validate().
  540. *
  541. * Returns: 0 on success, negative error code on failure.
  542. */
  543. static inline int
  544. drm_gpuvm_exec_validate(struct drm_gpuvm_exec *vm_exec)
  545. {
  546. return drm_gpuvm_validate(vm_exec->vm, &vm_exec->exec);
  547. }
  548. /**
  549. * struct drm_gpuvm_bo - structure representing a &drm_gpuvm and
  550. * &drm_gem_object combination
  551. *
  552. * This structure is an abstraction representing a &drm_gpuvm and
  553. * &drm_gem_object combination. It serves as an indirection to accelerate
  554. * iterating all &drm_gpuvas within a &drm_gpuvm backed by the same
  555. * &drm_gem_object.
  556. *
  557. * Furthermore it is used cache evicted GEM objects for a certain GPU-VM to
  558. * accelerate validation.
  559. *
  560. * Typically, drivers want to create an instance of a struct drm_gpuvm_bo once
  561. * a GEM object is mapped first in a GPU-VM and release the instance once the
  562. * last mapping of the GEM object in this GPU-VM is unmapped.
  563. */
  564. struct drm_gpuvm_bo {
  565. /**
  566. * @vm: The &drm_gpuvm the @obj is mapped in. This is a reference
  567. * counted pointer.
  568. */
  569. struct drm_gpuvm *vm;
  570. /**
  571. * @obj: The &drm_gem_object being mapped in @vm. This is a reference
  572. * counted pointer.
  573. */
  574. struct drm_gem_object *obj;
  575. /**
  576. * @evicted: Indicates whether the &drm_gem_object is evicted; field
  577. * protected by the &drm_gem_object's dma-resv lock.
  578. */
  579. bool evicted;
  580. /**
  581. * @kref: The reference count for this &drm_gpuvm_bo.
  582. */
  583. struct kref kref;
  584. /**
  585. * @list: Structure containing all &list_heads.
  586. */
  587. struct {
  588. /**
  589. * @list.gpuva: The list of linked &drm_gpuvas.
  590. *
  591. * It is safe to access entries from this list as long as the
  592. * GEM's gpuva lock is held. See also struct drm_gem_object.
  593. */
  594. struct list_head gpuva;
  595. /**
  596. * @list.entry: Structure containing all &list_heads serving as
  597. * entry.
  598. */
  599. struct {
  600. /**
  601. * @list.entry.gem: List entry to attach to the
  602. * &drm_gem_objects gpuva list.
  603. */
  604. struct list_head gem;
  605. /**
  606. * @list.entry.evict: List entry to attach to the
  607. * &drm_gpuvms extobj list.
  608. */
  609. struct list_head extobj;
  610. /**
  611. * @list.entry.evict: List entry to attach to the
  612. * &drm_gpuvms evict list.
  613. */
  614. struct list_head evict;
  615. } entry;
  616. } list;
  617. };
  618. struct drm_gpuvm_bo *
  619. drm_gpuvm_bo_create(struct drm_gpuvm *gpuvm,
  620. struct drm_gem_object *obj);
  621. struct drm_gpuvm_bo *
  622. drm_gpuvm_bo_obtain(struct drm_gpuvm *gpuvm,
  623. struct drm_gem_object *obj);
  624. struct drm_gpuvm_bo *
  625. drm_gpuvm_bo_obtain_prealloc(struct drm_gpuvm_bo *vm_bo);
  626. /**
  627. * drm_gpuvm_bo_get() - acquire a struct drm_gpuvm_bo reference
  628. * @vm_bo: the &drm_gpuvm_bo to acquire the reference of
  629. *
  630. * This function acquires an additional reference to @vm_bo. It is illegal to
  631. * call this without already holding a reference. No locks required.
  632. *
  633. * Returns: the &struct vm_bo pointer
  634. */
  635. static inline struct drm_gpuvm_bo *
  636. drm_gpuvm_bo_get(struct drm_gpuvm_bo *vm_bo)
  637. {
  638. kref_get(&vm_bo->kref);
  639. return vm_bo;
  640. }
  641. bool drm_gpuvm_bo_put(struct drm_gpuvm_bo *vm_bo);
  642. struct drm_gpuvm_bo *
  643. drm_gpuvm_bo_find(struct drm_gpuvm *gpuvm,
  644. struct drm_gem_object *obj);
  645. void drm_gpuvm_bo_evict(struct drm_gpuvm_bo *vm_bo, bool evict);
  646. /**
  647. * drm_gpuvm_bo_gem_evict() - add/remove all &drm_gpuvm_bo's in the list
  648. * to/from the &drm_gpuvms evicted list
  649. * @obj: the &drm_gem_object
  650. * @evict: indicates whether @obj is evicted
  651. *
  652. * See drm_gpuvm_bo_evict().
  653. */
  654. static inline void
  655. drm_gpuvm_bo_gem_evict(struct drm_gem_object *obj, bool evict)
  656. {
  657. struct drm_gpuvm_bo *vm_bo;
  658. drm_gem_gpuva_assert_lock_held(obj);
  659. drm_gem_for_each_gpuvm_bo(vm_bo, obj)
  660. drm_gpuvm_bo_evict(vm_bo, evict);
  661. }
  662. void drm_gpuvm_bo_extobj_add(struct drm_gpuvm_bo *vm_bo);
  663. /**
  664. * drm_gpuvm_bo_for_each_va() - iterator to walk over a list of &drm_gpuva
  665. * @va__: &drm_gpuva structure to assign to in each iteration step
  666. * @vm_bo__: the &drm_gpuvm_bo the &drm_gpuva to walk are associated with
  667. *
  668. * This iterator walks over all &drm_gpuva structures associated with the
  669. * &drm_gpuvm_bo.
  670. *
  671. * The caller must hold the GEM's gpuva lock.
  672. */
  673. #define drm_gpuvm_bo_for_each_va(va__, vm_bo__) \
  674. list_for_each_entry(va__, &(vm_bo)->list.gpuva, gem.entry)
  675. /**
  676. * drm_gpuvm_bo_for_each_va_safe() - iterator to safely walk over a list of
  677. * &drm_gpuva
  678. * @va__: &drm_gpuva structure to assign to in each iteration step
  679. * @next__: &next &drm_gpuva to store the next step
  680. * @vm_bo__: the &drm_gpuvm_bo the &drm_gpuva to walk are associated with
  681. *
  682. * This iterator walks over all &drm_gpuva structures associated with the
  683. * &drm_gpuvm_bo. It is implemented with list_for_each_entry_safe(), hence
  684. * it is save against removal of elements.
  685. *
  686. * The caller must hold the GEM's gpuva lock.
  687. */
  688. #define drm_gpuvm_bo_for_each_va_safe(va__, next__, vm_bo__) \
  689. list_for_each_entry_safe(va__, next__, &(vm_bo)->list.gpuva, gem.entry)
  690. /**
  691. * enum drm_gpuva_op_type - GPU VA operation type
  692. *
  693. * Operations to alter the GPU VA mappings tracked by the &drm_gpuvm.
  694. */
  695. enum drm_gpuva_op_type {
  696. /**
  697. * @DRM_GPUVA_OP_MAP: the map op type
  698. */
  699. DRM_GPUVA_OP_MAP,
  700. /**
  701. * @DRM_GPUVA_OP_REMAP: the remap op type
  702. */
  703. DRM_GPUVA_OP_REMAP,
  704. /**
  705. * @DRM_GPUVA_OP_UNMAP: the unmap op type
  706. */
  707. DRM_GPUVA_OP_UNMAP,
  708. /**
  709. * @DRM_GPUVA_OP_PREFETCH: the prefetch op type
  710. */
  711. DRM_GPUVA_OP_PREFETCH,
  712. };
  713. /**
  714. * struct drm_gpuva_op_map - GPU VA map operation
  715. *
  716. * This structure represents a single map operation generated by the
  717. * DRM GPU VA manager.
  718. */
  719. struct drm_gpuva_op_map {
  720. /**
  721. * @va: structure containing address and range of a map
  722. * operation
  723. */
  724. struct {
  725. /**
  726. * @va.addr: the base address of the new mapping
  727. */
  728. u64 addr;
  729. /**
  730. * @va.range: the range of the new mapping
  731. */
  732. u64 range;
  733. } va;
  734. /**
  735. * @gem: structure containing the &drm_gem_object and it's offset
  736. */
  737. struct {
  738. /**
  739. * @gem.offset: the offset within the &drm_gem_object
  740. */
  741. u64 offset;
  742. /**
  743. * @gem.obj: the &drm_gem_object to map
  744. */
  745. struct drm_gem_object *obj;
  746. } gem;
  747. };
  748. /**
  749. * struct drm_gpuva_op_unmap - GPU VA unmap operation
  750. *
  751. * This structure represents a single unmap operation generated by the
  752. * DRM GPU VA manager.
  753. */
  754. struct drm_gpuva_op_unmap {
  755. /**
  756. * @va: the &drm_gpuva to unmap
  757. */
  758. struct drm_gpuva *va;
  759. /**
  760. * @keep:
  761. *
  762. * Indicates whether this &drm_gpuva is physically contiguous with the
  763. * original mapping request.
  764. *
  765. * Optionally, if &keep is set, drivers may keep the actual page table
  766. * mappings for this &drm_gpuva, adding the missing page table entries
  767. * only and update the &drm_gpuvm accordingly.
  768. */
  769. bool keep;
  770. };
  771. /**
  772. * struct drm_gpuva_op_remap - GPU VA remap operation
  773. *
  774. * This represents a single remap operation generated by the DRM GPU VA manager.
  775. *
  776. * A remap operation is generated when an existing GPU VA mmapping is split up
  777. * by inserting a new GPU VA mapping or by partially unmapping existent
  778. * mapping(s), hence it consists of a maximum of two map and one unmap
  779. * operation.
  780. *
  781. * The @unmap operation takes care of removing the original existing mapping.
  782. * @prev is used to remap the preceding part, @next the subsequent part.
  783. *
  784. * If either a new mapping's start address is aligned with the start address
  785. * of the old mapping or the new mapping's end address is aligned with the
  786. * end address of the old mapping, either @prev or @next is NULL.
  787. *
  788. * Note, the reason for a dedicated remap operation, rather than arbitrary
  789. * unmap and map operations, is to give drivers the chance of extracting driver
  790. * specific data for creating the new mappings from the unmap operations's
  791. * &drm_gpuva structure which typically is embedded in larger driver specific
  792. * structures.
  793. */
  794. struct drm_gpuva_op_remap {
  795. /**
  796. * @prev: the preceding part of a split mapping
  797. */
  798. struct drm_gpuva_op_map *prev;
  799. /**
  800. * @next: the subsequent part of a split mapping
  801. */
  802. struct drm_gpuva_op_map *next;
  803. /**
  804. * @unmap: the unmap operation for the original existing mapping
  805. */
  806. struct drm_gpuva_op_unmap *unmap;
  807. };
  808. /**
  809. * struct drm_gpuva_op_prefetch - GPU VA prefetch operation
  810. *
  811. * This structure represents a single prefetch operation generated by the
  812. * DRM GPU VA manager.
  813. */
  814. struct drm_gpuva_op_prefetch {
  815. /**
  816. * @va: the &drm_gpuva to prefetch
  817. */
  818. struct drm_gpuva *va;
  819. };
  820. /**
  821. * struct drm_gpuva_op - GPU VA operation
  822. *
  823. * This structure represents a single generic operation.
  824. *
  825. * The particular type of the operation is defined by @op.
  826. */
  827. struct drm_gpuva_op {
  828. /**
  829. * @entry:
  830. *
  831. * The &list_head used to distribute instances of this struct within
  832. * &drm_gpuva_ops.
  833. */
  834. struct list_head entry;
  835. /**
  836. * @op: the type of the operation
  837. */
  838. enum drm_gpuva_op_type op;
  839. union {
  840. /**
  841. * @map: the map operation
  842. */
  843. struct drm_gpuva_op_map map;
  844. /**
  845. * @remap: the remap operation
  846. */
  847. struct drm_gpuva_op_remap remap;
  848. /**
  849. * @unmap: the unmap operation
  850. */
  851. struct drm_gpuva_op_unmap unmap;
  852. /**
  853. * @prefetch: the prefetch operation
  854. */
  855. struct drm_gpuva_op_prefetch prefetch;
  856. };
  857. };
  858. /**
  859. * struct drm_gpuva_ops - wraps a list of &drm_gpuva_op
  860. */
  861. struct drm_gpuva_ops {
  862. /**
  863. * @list: the &list_head
  864. */
  865. struct list_head list;
  866. };
  867. /**
  868. * drm_gpuva_for_each_op() - iterator to walk over &drm_gpuva_ops
  869. * @op: &drm_gpuva_op to assign in each iteration step
  870. * @ops: &drm_gpuva_ops to walk
  871. *
  872. * This iterator walks over all ops within a given list of operations.
  873. */
  874. #define drm_gpuva_for_each_op(op, ops) list_for_each_entry(op, &(ops)->list, entry)
  875. /**
  876. * drm_gpuva_for_each_op_safe() - iterator to safely walk over &drm_gpuva_ops
  877. * @op: &drm_gpuva_op to assign in each iteration step
  878. * @next: &next &drm_gpuva_op to store the next step
  879. * @ops: &drm_gpuva_ops to walk
  880. *
  881. * This iterator walks over all ops within a given list of operations. It is
  882. * implemented with list_for_each_safe(), so save against removal of elements.
  883. */
  884. #define drm_gpuva_for_each_op_safe(op, next, ops) \
  885. list_for_each_entry_safe(op, next, &(ops)->list, entry)
  886. /**
  887. * drm_gpuva_for_each_op_from_reverse() - iterate backwards from the given point
  888. * @op: &drm_gpuva_op to assign in each iteration step
  889. * @ops: &drm_gpuva_ops to walk
  890. *
  891. * This iterator walks over all ops within a given list of operations beginning
  892. * from the given operation in reverse order.
  893. */
  894. #define drm_gpuva_for_each_op_from_reverse(op, ops) \
  895. list_for_each_entry_from_reverse(op, &(ops)->list, entry)
  896. /**
  897. * drm_gpuva_for_each_op_reverse - iterator to walk over &drm_gpuva_ops in reverse
  898. * @op: &drm_gpuva_op to assign in each iteration step
  899. * @ops: &drm_gpuva_ops to walk
  900. *
  901. * This iterator walks over all ops within a given list of operations in reverse
  902. */
  903. #define drm_gpuva_for_each_op_reverse(op, ops) \
  904. list_for_each_entry_reverse(op, &(ops)->list, entry)
  905. /**
  906. * drm_gpuva_first_op() - returns the first &drm_gpuva_op from &drm_gpuva_ops
  907. * @ops: the &drm_gpuva_ops to get the fist &drm_gpuva_op from
  908. */
  909. #define drm_gpuva_first_op(ops) \
  910. list_first_entry(&(ops)->list, struct drm_gpuva_op, entry)
  911. /**
  912. * drm_gpuva_last_op() - returns the last &drm_gpuva_op from &drm_gpuva_ops
  913. * @ops: the &drm_gpuva_ops to get the last &drm_gpuva_op from
  914. */
  915. #define drm_gpuva_last_op(ops) \
  916. list_last_entry(&(ops)->list, struct drm_gpuva_op, entry)
  917. /**
  918. * drm_gpuva_prev_op() - previous &drm_gpuva_op in the list
  919. * @op: the current &drm_gpuva_op
  920. */
  921. #define drm_gpuva_prev_op(op) list_prev_entry(op, entry)
  922. /**
  923. * drm_gpuva_next_op() - next &drm_gpuva_op in the list
  924. * @op: the current &drm_gpuva_op
  925. */
  926. #define drm_gpuva_next_op(op) list_next_entry(op, entry)
  927. struct drm_gpuva_ops *
  928. drm_gpuvm_sm_map_ops_create(struct drm_gpuvm *gpuvm,
  929. u64 addr, u64 range,
  930. struct drm_gem_object *obj, u64 offset);
  931. struct drm_gpuva_ops *
  932. drm_gpuvm_sm_unmap_ops_create(struct drm_gpuvm *gpuvm,
  933. u64 addr, u64 range);
  934. struct drm_gpuva_ops *
  935. drm_gpuvm_prefetch_ops_create(struct drm_gpuvm *gpuvm,
  936. u64 addr, u64 range);
  937. struct drm_gpuva_ops *
  938. drm_gpuvm_bo_unmap_ops_create(struct drm_gpuvm_bo *vm_bo);
  939. void drm_gpuva_ops_free(struct drm_gpuvm *gpuvm,
  940. struct drm_gpuva_ops *ops);
  941. static inline void drm_gpuva_init_from_op(struct drm_gpuva *va,
  942. struct drm_gpuva_op_map *op)
  943. {
  944. drm_gpuva_init(va, op->va.addr, op->va.range,
  945. op->gem.obj, op->gem.offset);
  946. }
  947. /**
  948. * struct drm_gpuvm_ops - callbacks for split/merge steps
  949. *
  950. * This structure defines the callbacks used by &drm_gpuvm_sm_map and
  951. * &drm_gpuvm_sm_unmap to provide the split/merge steps for map and unmap
  952. * operations to drivers.
  953. */
  954. struct drm_gpuvm_ops {
  955. /**
  956. * @vm_free: called when the last reference of a struct drm_gpuvm is
  957. * dropped
  958. *
  959. * This callback is mandatory.
  960. */
  961. void (*vm_free)(struct drm_gpuvm *gpuvm);
  962. /**
  963. * @op_alloc: called when the &drm_gpuvm allocates
  964. * a struct drm_gpuva_op
  965. *
  966. * Some drivers may want to embed struct drm_gpuva_op into driver
  967. * specific structures. By implementing this callback drivers can
  968. * allocate memory accordingly.
  969. *
  970. * This callback is optional.
  971. */
  972. struct drm_gpuva_op *(*op_alloc)(void);
  973. /**
  974. * @op_free: called when the &drm_gpuvm frees a
  975. * struct drm_gpuva_op
  976. *
  977. * Some drivers may want to embed struct drm_gpuva_op into driver
  978. * specific structures. By implementing this callback drivers can
  979. * free the previously allocated memory accordingly.
  980. *
  981. * This callback is optional.
  982. */
  983. void (*op_free)(struct drm_gpuva_op *op);
  984. /**
  985. * @vm_bo_alloc: called when the &drm_gpuvm allocates
  986. * a struct drm_gpuvm_bo
  987. *
  988. * Some drivers may want to embed struct drm_gpuvm_bo into driver
  989. * specific structures. By implementing this callback drivers can
  990. * allocate memory accordingly.
  991. *
  992. * This callback is optional.
  993. */
  994. struct drm_gpuvm_bo *(*vm_bo_alloc)(void);
  995. /**
  996. * @vm_bo_free: called when the &drm_gpuvm frees a
  997. * struct drm_gpuvm_bo
  998. *
  999. * Some drivers may want to embed struct drm_gpuvm_bo into driver
  1000. * specific structures. By implementing this callback drivers can
  1001. * free the previously allocated memory accordingly.
  1002. *
  1003. * This callback is optional.
  1004. */
  1005. void (*vm_bo_free)(struct drm_gpuvm_bo *vm_bo);
  1006. /**
  1007. * @vm_bo_validate: called from drm_gpuvm_validate()
  1008. *
  1009. * Drivers receive this callback for every evicted &drm_gem_object being
  1010. * mapped in the corresponding &drm_gpuvm.
  1011. *
  1012. * Typically, drivers would call their driver specific variant of
  1013. * ttm_bo_validate() from within this callback.
  1014. */
  1015. int (*vm_bo_validate)(struct drm_gpuvm_bo *vm_bo,
  1016. struct drm_exec *exec);
  1017. /**
  1018. * @sm_step_map: called from &drm_gpuvm_sm_map to finally insert the
  1019. * mapping once all previous steps were completed
  1020. *
  1021. * The &priv pointer matches the one the driver passed to
  1022. * &drm_gpuvm_sm_map or &drm_gpuvm_sm_unmap, respectively.
  1023. *
  1024. * Can be NULL if &drm_gpuvm_sm_map is used.
  1025. */
  1026. int (*sm_step_map)(struct drm_gpuva_op *op, void *priv);
  1027. /**
  1028. * @sm_step_remap: called from &drm_gpuvm_sm_map and
  1029. * &drm_gpuvm_sm_unmap to split up an existent mapping
  1030. *
  1031. * This callback is called when existent mapping needs to be split up.
  1032. * This is the case when either a newly requested mapping overlaps or
  1033. * is enclosed by an existent mapping or a partial unmap of an existent
  1034. * mapping is requested.
  1035. *
  1036. * The &priv pointer matches the one the driver passed to
  1037. * &drm_gpuvm_sm_map or &drm_gpuvm_sm_unmap, respectively.
  1038. *
  1039. * Can be NULL if neither &drm_gpuvm_sm_map nor &drm_gpuvm_sm_unmap is
  1040. * used.
  1041. */
  1042. int (*sm_step_remap)(struct drm_gpuva_op *op, void *priv);
  1043. /**
  1044. * @sm_step_unmap: called from &drm_gpuvm_sm_map and
  1045. * &drm_gpuvm_sm_unmap to unmap an existent mapping
  1046. *
  1047. * This callback is called when existent mapping needs to be unmapped.
  1048. * This is the case when either a newly requested mapping encloses an
  1049. * existent mapping or an unmap of an existent mapping is requested.
  1050. *
  1051. * The &priv pointer matches the one the driver passed to
  1052. * &drm_gpuvm_sm_map or &drm_gpuvm_sm_unmap, respectively.
  1053. *
  1054. * Can be NULL if neither &drm_gpuvm_sm_map nor &drm_gpuvm_sm_unmap is
  1055. * used.
  1056. */
  1057. int (*sm_step_unmap)(struct drm_gpuva_op *op, void *priv);
  1058. };
  1059. int drm_gpuvm_sm_map(struct drm_gpuvm *gpuvm, void *priv,
  1060. u64 addr, u64 range,
  1061. struct drm_gem_object *obj, u64 offset);
  1062. int drm_gpuvm_sm_unmap(struct drm_gpuvm *gpuvm, void *priv,
  1063. u64 addr, u64 range);
  1064. void drm_gpuva_map(struct drm_gpuvm *gpuvm,
  1065. struct drm_gpuva *va,
  1066. struct drm_gpuva_op_map *op);
  1067. void drm_gpuva_remap(struct drm_gpuva *prev,
  1068. struct drm_gpuva *next,
  1069. struct drm_gpuva_op_remap *op);
  1070. void drm_gpuva_unmap(struct drm_gpuva_op_unmap *op);
  1071. /**
  1072. * drm_gpuva_op_remap_to_unmap_range() - Helper to get the start and range of
  1073. * the unmap stage of a remap op.
  1074. * @op: Remap op.
  1075. * @start_addr: Output pointer for the start of the required unmap.
  1076. * @range: Output pointer for the length of the required unmap.
  1077. *
  1078. * The given start address and range will be set such that they represent the
  1079. * range of the address space that was previously covered by the mapping being
  1080. * re-mapped, but is now empty.
  1081. */
  1082. static inline void
  1083. drm_gpuva_op_remap_to_unmap_range(const struct drm_gpuva_op_remap *op,
  1084. u64 *start_addr, u64 *range)
  1085. {
  1086. const u64 va_start = op->prev ?
  1087. op->prev->va.addr + op->prev->va.range :
  1088. op->unmap->va->va.addr;
  1089. const u64 va_end = op->next ?
  1090. op->next->va.addr :
  1091. op->unmap->va->va.addr + op->unmap->va->va.range;
  1092. if (start_addr)
  1093. *start_addr = va_start;
  1094. if (range)
  1095. *range = va_end - va_start;
  1096. }
  1097. #endif /* __DRM_GPUVM_H__ */