Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/doc: Add PRIME function references

For giant hilarity the DocBook reference overview is only generated
when in a level 2 section, not in a level 3 section. So we need to
move this up a bit as a side-by-side section to the main PRIME
documentation.

Whatever.

To have a complete set of references add the missing kerneldoc for all
functions exported to modules with the exception of the file private
init/destroy functions - drivers have no business calling those, so
let's just drop the EXPORT_SYMBOL instead.

Also reflow the function parameters to align correctly and break at 80
chars - my OCD couldn't stand them while writing the kerneldoc ;-)

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

+94 -22
+5 -1
Documentation/DocBook/drm.tmpl
··· 898 898 </para> 899 899 </sect3> 900 900 <sect3> 901 - <title>PRIME Helper Functions Reference</title> 901 + <title>PRIME Helper Functions</title> 902 902 !Pdrivers/gpu/drm/drm_prime.c PRIME Helpers 903 903 </sect3> 904 + </sect2> 905 + <sect2> 906 + <title>PRIME Function References</title> 907 + !Edrivers/gpu/drm/drm_prime.c 904 908 </sect2> 905 909 </sect1> 906 910
+89 -21
drivers/gpu/drm/drm_prime.c
··· 68 68 enum dma_data_direction dir; 69 69 }; 70 70 71 - static int drm_prime_add_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle) 71 + static int drm_prime_add_buf_handle(struct drm_prime_file_private *prime_fpriv, 72 + struct dma_buf *dma_buf, uint32_t handle) 72 73 { 73 74 struct drm_prime_member *member; 74 75 ··· 175 174 } 176 175 177 176 static struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach, 178 - enum dma_data_direction dir) 177 + enum dma_data_direction dir) 179 178 { 180 179 struct drm_prime_attachment *prime_attach = attach->priv; 181 180 struct drm_gem_object *obj = attach->dmabuf->priv; ··· 212 211 } 213 212 214 213 static void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach, 215 - struct sg_table *sgt, enum dma_data_direction dir) 214 + struct sg_table *sgt, 215 + enum dma_data_direction dir) 216 216 { 217 217 /* nothing to be done here */ 218 218 } 219 219 220 + /** 221 + * drm_gem_dmabuf_release - dma_buf release implementation for GEM 222 + * @dma_buf: buffer to be released 223 + * 224 + * Generic release function for dma_bufs exported as PRIME buffers. GEM drivers 225 + * must use this in their dma_buf ops structure as the release callback. 226 + */ 220 227 void drm_gem_dmabuf_release(struct dma_buf *dma_buf) 221 228 { 222 229 struct drm_gem_object *obj = dma_buf->priv; ··· 251 242 } 252 243 253 244 static void *drm_gem_dmabuf_kmap_atomic(struct dma_buf *dma_buf, 254 - unsigned long page_num) 245 + unsigned long page_num) 255 246 { 256 247 return NULL; 257 248 } 258 249 259 250 static void drm_gem_dmabuf_kunmap_atomic(struct dma_buf *dma_buf, 260 - unsigned long page_num, void *addr) 251 + unsigned long page_num, void *addr) 261 252 { 262 253 263 254 } 264 255 static void *drm_gem_dmabuf_kmap(struct dma_buf *dma_buf, 265 - unsigned long page_num) 256 + unsigned long page_num) 266 257 { 267 258 return NULL; 268 259 } 269 260 270 261 static void drm_gem_dmabuf_kunmap(struct dma_buf *dma_buf, 271 - unsigned long page_num, void *addr) 262 + unsigned long page_num, void *addr) 272 263 { 273 264 274 265 } 275 266 276 267 static int drm_gem_dmabuf_mmap(struct dma_buf *dma_buf, 277 - struct vm_area_struct *vma) 268 + struct vm_area_struct *vma) 278 269 { 279 270 struct drm_gem_object *obj = dma_buf->priv; 280 271 struct drm_device *dev = obj->dev; ··· 324 315 * driver's scatter/gather table 325 316 */ 326 317 318 + /** 319 + * drm_gem_prime_export - helper library implemention of the export callback 320 + * @dev: drm_device to export from 321 + * @obj: GEM object to export 322 + * @flags: flags like DRM_CLOEXEC 323 + * 324 + * This is the implementation of the gem_prime_export functions for GEM drivers 325 + * using the PRIME helpers. 326 + */ 327 327 struct dma_buf *drm_gem_prime_export(struct drm_device *dev, 328 328 struct drm_gem_object *obj, int flags) 329 329 { ··· 373 355 return dmabuf; 374 356 } 375 357 358 + /** 359 + * drm_gem_prime_handle_to_fd - PRIME export function for GEM drivers 360 + * @dev: dev to export the buffer from 361 + * @file_priv: drm file-private structure 362 + * @handle: buffer handle to export 363 + * @flags: flags like DRM_CLOEXEC 364 + * @prime_fd: pointer to storage for the fd id of the create dma-buf 365 + * 366 + * This is the PRIME export function which must be used mandatorily by GEM 367 + * drivers to ensure correct lifetime management of the underlying GEM object. 368 + * The actual exporting from GEM object to a dma-buf is done through the 369 + * gem_prime_export driver callback. 370 + */ 376 371 int drm_gem_prime_handle_to_fd(struct drm_device *dev, 377 - struct drm_file *file_priv, uint32_t handle, uint32_t flags, 378 - int *prime_fd) 372 + struct drm_file *file_priv, uint32_t handle, 373 + uint32_t flags, 374 + int *prime_fd) 379 375 { 380 376 struct drm_gem_object *obj; 381 377 int ret = 0; ··· 473 441 } 474 442 EXPORT_SYMBOL(drm_gem_prime_handle_to_fd); 475 443 444 + /** 445 + * drm_gem_prime_import - helper library implemention of the import callback 446 + * @dev: drm_device to import into 447 + * @dma_buf: dma-buf object to import 448 + * 449 + * This is the implementation of the gem_prime_import functions for GEM drivers 450 + * using the PRIME helpers. 451 + */ 476 452 struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, 477 453 struct dma_buf *dma_buf) 478 454 { ··· 536 496 } 537 497 EXPORT_SYMBOL(drm_gem_prime_import); 538 498 499 + /** 500 + * drm_gem_prime_fd_to_handle - PRIME import function for GEM drivers 501 + * @dev: dev to export the buffer from 502 + * @file_priv: drm file-private structure 503 + * @prime_fd: fd id of the dma-buf which should be imported 504 + * @handle: pointer to storage for the handle of the imported buffer object 505 + * 506 + * This is the PRIME import function which must be used mandatorily by GEM 507 + * drivers to ensure correct lifetime management of the underlying GEM object. 508 + * The actual importing of GEM object from the dma-buf is done through the 509 + * gem_import_export driver callback. 510 + */ 539 511 int drm_gem_prime_fd_to_handle(struct drm_device *dev, 540 - struct drm_file *file_priv, int prime_fd, uint32_t *handle) 512 + struct drm_file *file_priv, int prime_fd, 513 + uint32_t *handle) 541 514 { 542 515 struct dma_buf *dma_buf; 543 516 struct drm_gem_object *obj; ··· 651 598 args->fd, &args->handle); 652 599 } 653 600 654 - /* 655 - * drm_prime_pages_to_sg 601 + /** 602 + * drm_prime_pages_to_sg - converts a page array into an sg list 603 + * @pages: pointer to the array of page pointers to convert 604 + * @nr_pages: length of the page vector 656 605 * 657 - * this helper creates an sg table object from a set of pages 606 + * This helper creates an sg table object from a set of pages 658 607 * the driver is responsible for mapping the pages into the 659 - * importers address space 608 + * importers address space for use with dma_buf itself. 660 609 */ 661 610 struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages) 662 611 { ··· 683 628 } 684 629 EXPORT_SYMBOL(drm_prime_pages_to_sg); 685 630 686 - /* export an sg table into an array of pages and addresses 687 - this is currently required by the TTM driver in order to do correct fault 688 - handling */ 631 + /** 632 + * drm_prime_sg_to_page_addr_arrays - convert an sg table into a page array 633 + * @sgt: scatter-gather table to convert 634 + * @pages: array of page pointers to store the page array in 635 + * @addrs: optional array to store the dma bus address of each page 636 + * @max_pages: size of both the passed-in arrays 637 + * 638 + * Exports an sg table into an array of pages and addresses. This is currently 639 + * required by the TTM driver in order to do correct fault handling. 640 + */ 689 641 int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages, 690 642 dma_addr_t *addrs, int max_pages) 691 643 { ··· 725 663 return 0; 726 664 } 727 665 EXPORT_SYMBOL(drm_prime_sg_to_page_addr_arrays); 728 - /* helper function to cleanup a GEM/prime object */ 666 + 667 + /** 668 + * drm_prime_gem_destroy - helper to clean up a PRIME-imported GEM object 669 + * @obj: GEM object which was created from a dma-buf 670 + * @sg: the sg-table which was pinned at import time 671 + * 672 + * This is the cleanup functions which GEM drivers need to call when they use 673 + * @drm_gem_prime_import to import dma-bufs. 674 + */ 729 675 void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg) 730 676 { 731 677 struct dma_buf_attachment *attach; ··· 753 683 INIT_LIST_HEAD(&prime_fpriv->head); 754 684 mutex_init(&prime_fpriv->lock); 755 685 } 756 - EXPORT_SYMBOL(drm_prime_init_file_private); 757 686 758 687 void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv) 759 688 { 760 689 /* by now drm_gem_release should've made sure the list is empty */ 761 690 WARN_ON(!list_empty(&prime_fpriv->head)); 762 691 } 763 - EXPORT_SYMBOL(drm_prime_destroy_file_private);