1/************************************************************************** 2 * 3 * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 24 * USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27/* 28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> 29 */ 30 31#ifndef _TTM_BO_API_H_ 32#define _TTM_BO_API_H_ 33 34#include <drm/drm_gem.h> 35#include <drm/drm_hashtab.h> 36#include <drm/drm_vma_manager.h> 37#include <linux/kref.h> 38#include <linux/list.h> 39#include <linux/wait.h> 40#include <linux/mutex.h> 41#include <linux/mm.h> 42#include <linux/bitmap.h> 43#include <linux/dma-resv.h> 44 45struct ttm_bo_global; 46 47struct ttm_bo_device; 48 49struct drm_mm_node; 50 51struct ttm_placement; 52 53struct ttm_place; 54 55struct ttm_lru_bulk_move; 56 57/** 58 * struct ttm_bus_placement 59 * 60 * @addr: mapped virtual address 61 * @base: bus base address 62 * @is_iomem: is this io memory ? 63 * @size: size in byte 64 * @offset: offset from the base address 65 * @io_reserved_vm: The VM system has a refcount in @io_reserved_count 66 * @io_reserved_count: Refcounting the numbers of callers to ttm_mem_io_reserve 67 * 68 * Structure indicating the bus placement of an object. 69 */ 70struct ttm_bus_placement { 71 void *addr; 72 phys_addr_t base; 73 unsigned long size; 74 unsigned long offset; 75 bool is_iomem; 76 bool io_reserved_vm; 77 uint64_t io_reserved_count; 78}; 79 80 81/** 82 * struct ttm_mem_reg 83 * 84 * @mm_node: Memory manager node. 85 * @size: Requested size of memory region. 86 * @num_pages: Actual size of memory region in pages. 87 * @page_alignment: Page alignment. 88 * @placement: Placement flags. 89 * @bus: Placement on io bus accessible to the CPU 90 * 91 * Structure indicating the placement and space resources used by a 92 * buffer object. 93 */ 94 95struct ttm_mem_reg { 96 void *mm_node; 97 unsigned long start; 98 unsigned long size; 99 unsigned long num_pages; 100 uint32_t page_alignment; 101 uint32_t mem_type; 102 uint32_t placement; 103 struct ttm_bus_placement bus; 104}; 105 106/** 107 * enum ttm_bo_type 108 * 109 * @ttm_bo_type_device: These are 'normal' buffers that can 110 * be mmapped by user space. Each of these bos occupy a slot in the 111 * device address space, that can be used for normal vm operations. 112 * 113 * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers, 114 * but they cannot be accessed from user-space. For kernel-only use. 115 * 116 * @ttm_bo_type_sg: Buffer made from dmabuf sg table shared with another 117 * driver. 118 */ 119 120enum ttm_bo_type { 121 ttm_bo_type_device, 122 ttm_bo_type_kernel, 123 ttm_bo_type_sg 124}; 125 126struct ttm_tt; 127 128/** 129 * struct ttm_buffer_object 130 * 131 * @base: drm_gem_object superclass data. 132 * @bdev: Pointer to the buffer object device structure. 133 * @type: The bo type. 134 * @destroy: Destruction function. If NULL, kfree is used. 135 * @num_pages: Actual number of pages. 136 * @acc_size: Accounted size for this object. 137 * @kref: Reference count of this buffer object. When this refcount reaches 138 * zero, the object is put on the delayed delete list. 139 * @list_kref: List reference count of this buffer object. This member is 140 * used to avoid destruction while the buffer object is still on a list. 141 * Lru lists may keep one refcount, the delayed delete list, and kref != 0 142 * keeps one refcount. When this refcount reaches zero, 143 * the object is destroyed. 144 * @mem: structure describing current placement. 145 * @persistent_swap_storage: Usually the swap storage is deleted for buffers 146 * pinned in physical memory. If this behaviour is not desired, this member 147 * holds a pointer to a persistent shmem object. 148 * @ttm: TTM structure holding system pages. 149 * @evicted: Whether the object was evicted without user-space knowing. 150 * @lru: List head for the lru list. 151 * @ddestroy: List head for the delayed destroy list. 152 * @swap: List head for swap LRU list. 153 * @moving: Fence set when BO is moving 154 * @offset: The current GPU offset, which can have different meanings 155 * depending on the memory type. For SYSTEM type memory, it should be 0. 156 * @cur_placement: Hint of current placement. 157 * @wu_mutex: Wait unreserved mutex. 158 * 159 * Base class for TTM buffer object, that deals with data placement and CPU 160 * mappings. GPU mappings are really up to the driver, but for simpler GPUs 161 * the driver can usually use the placement offset @offset directly as the 162 * GPU virtual address. For drivers implementing multiple 163 * GPU memory manager contexts, the driver should manage the address space 164 * in these contexts separately and use these objects to get the correct 165 * placement and caching for these GPU maps. This makes it possible to use 166 * these objects for even quite elaborate memory management schemes. 167 * The destroy member, the API visibility of this object makes it possible 168 * to derive driver specific types. 169 */ 170 171struct ttm_buffer_object { 172 struct drm_gem_object base; 173 174 /** 175 * Members constant at init. 176 */ 177 178 struct ttm_bo_device *bdev; 179 enum ttm_bo_type type; 180 void (*destroy) (struct ttm_buffer_object *); 181 unsigned long num_pages; 182 size_t acc_size; 183 184 /** 185 * Members not needing protection. 186 */ 187 188 struct kref kref; 189 struct kref list_kref; 190 191 /** 192 * Members protected by the bo::resv::reserved lock. 193 */ 194 195 struct ttm_mem_reg mem; 196 struct file *persistent_swap_storage; 197 struct ttm_tt *ttm; 198 bool evicted; 199 200 /** 201 * Members protected by the bdev::lru_lock. 202 */ 203 204 struct list_head lru; 205 struct list_head ddestroy; 206 struct list_head swap; 207 struct list_head io_reserve_lru; 208 209 /** 210 * Members protected by a bo reservation. 211 */ 212 213 struct dma_fence *moving; 214 unsigned priority; 215 216 /** 217 * Special members that are protected by the reserve lock 218 * and the bo::lock when written to. Can be read with 219 * either of these locks held. 220 */ 221 222 uint64_t offset; /* GPU address space is independent of CPU word size */ 223 224 struct sg_table *sg; 225 226 struct mutex wu_mutex; 227}; 228 229/** 230 * struct ttm_bo_kmap_obj 231 * 232 * @virtual: The current kernel virtual address. 233 * @page: The page when kmap'ing a single page. 234 * @bo_kmap_type: Type of bo_kmap. 235 * 236 * Object describing a kernel mapping. Since a TTM bo may be located 237 * in various memory types with various caching policies, the 238 * mapping can either be an ioremap, a vmap, a kmap or part of a 239 * premapped region. 240 */ 241 242#define TTM_BO_MAP_IOMEM_MASK 0x80 243struct ttm_bo_kmap_obj { 244 void *virtual; 245 struct page *page; 246 enum { 247 ttm_bo_map_iomap = 1 | TTM_BO_MAP_IOMEM_MASK, 248 ttm_bo_map_vmap = 2, 249 ttm_bo_map_kmap = 3, 250 ttm_bo_map_premapped = 4 | TTM_BO_MAP_IOMEM_MASK, 251 } bo_kmap_type; 252 struct ttm_buffer_object *bo; 253}; 254 255/** 256 * struct ttm_operation_ctx 257 * 258 * @interruptible: Sleep interruptible if sleeping. 259 * @no_wait_gpu: Return immediately if the GPU is busy. 260 * @resv: Reservation object to allow reserved evictions with. 261 * @flags: Including the following flags 262 * 263 * Context for TTM operations like changing buffer placement or general memory 264 * allocation. 265 */ 266struct ttm_operation_ctx { 267 bool interruptible; 268 bool no_wait_gpu; 269 struct dma_resv *resv; 270 uint64_t bytes_moved; 271 uint32_t flags; 272}; 273 274/* Allow eviction of reserved BOs */ 275#define TTM_OPT_FLAG_ALLOW_RES_EVICT 0x1 276/* when serving page fault or suspend, allow alloc anyway */ 277#define TTM_OPT_FLAG_FORCE_ALLOC 0x2 278 279/** 280 * ttm_bo_get - reference a struct ttm_buffer_object 281 * 282 * @bo: The buffer object. 283 */ 284static inline void ttm_bo_get(struct ttm_buffer_object *bo) 285{ 286 kref_get(&bo->kref); 287} 288 289/** 290 * ttm_bo_get_unless_zero - reference a struct ttm_buffer_object unless 291 * its refcount has already reached zero. 292 * @bo: The buffer object. 293 * 294 * Used to reference a TTM buffer object in lookups where the object is removed 295 * from the lookup structure during the destructor and for RCU lookups. 296 * 297 * Returns: @bo if the referencing was successful, NULL otherwise. 298 */ 299static inline __must_check struct ttm_buffer_object * 300ttm_bo_get_unless_zero(struct ttm_buffer_object *bo) 301{ 302 if (!kref_get_unless_zero(&bo->kref)) 303 return NULL; 304 return bo; 305} 306 307/** 308 * ttm_bo_wait - wait for buffer idle. 309 * 310 * @bo: The buffer object. 311 * @interruptible: Use interruptible wait. 312 * @no_wait: Return immediately if buffer is busy. 313 * 314 * This function must be called with the bo::mutex held, and makes 315 * sure any previous rendering to the buffer is completed. 316 * Note: It might be necessary to block validations before the 317 * wait by reserving the buffer. 318 * Returns -EBUSY if no_wait is true and the buffer is busy. 319 * Returns -ERESTARTSYS if interrupted by a signal. 320 */ 321int ttm_bo_wait(struct ttm_buffer_object *bo, bool interruptible, bool no_wait); 322 323/** 324 * ttm_bo_mem_compat - Check if proposed placement is compatible with a bo 325 * 326 * @placement: Return immediately if buffer is busy. 327 * @mem: The struct ttm_mem_reg indicating the region where the bo resides 328 * @new_flags: Describes compatible placement found 329 * 330 * Returns true if the placement is compatible 331 */ 332bool ttm_bo_mem_compat(struct ttm_placement *placement, struct ttm_mem_reg *mem, 333 uint32_t *new_flags); 334 335/** 336 * ttm_bo_validate 337 * 338 * @bo: The buffer object. 339 * @placement: Proposed placement for the buffer object. 340 * @ctx: validation parameters. 341 * 342 * Changes placement and caching policy of the buffer object 343 * according proposed placement. 344 * Returns 345 * -EINVAL on invalid proposed placement. 346 * -ENOMEM on out-of-memory condition. 347 * -EBUSY if no_wait is true and buffer busy. 348 * -ERESTARTSYS if interrupted by a signal. 349 */ 350int ttm_bo_validate(struct ttm_buffer_object *bo, 351 struct ttm_placement *placement, 352 struct ttm_operation_ctx *ctx); 353 354/** 355 * ttm_bo_put 356 * 357 * @bo: The buffer object. 358 * 359 * Unreference a buffer object. 360 */ 361void ttm_bo_put(struct ttm_buffer_object *bo); 362 363/** 364 * ttm_bo_move_to_lru_tail 365 * 366 * @bo: The buffer object. 367 * @bulk: optional bulk move structure to remember BO positions 368 * 369 * Move this BO to the tail of all lru lists used to lookup and reserve an 370 * object. This function must be called with struct ttm_bo_global::lru_lock 371 * held, and is used to make a BO less likely to be considered for eviction. 372 */ 373void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo, 374 struct ttm_lru_bulk_move *bulk); 375 376/** 377 * ttm_bo_bulk_move_lru_tail 378 * 379 * @bulk: bulk move structure 380 * 381 * Bulk move BOs to the LRU tail, only valid to use when driver makes sure that 382 * BO order never changes. Should be called with ttm_bo_global::lru_lock held. 383 */ 384void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk); 385 386/** 387 * ttm_bo_lock_delayed_workqueue 388 * 389 * Prevent the delayed workqueue from running. 390 * Returns 391 * True if the workqueue was queued at the time 392 */ 393int ttm_bo_lock_delayed_workqueue(struct ttm_bo_device *bdev); 394 395/** 396 * ttm_bo_unlock_delayed_workqueue 397 * 398 * Allows the delayed workqueue to run. 399 */ 400void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev, int resched); 401 402/** 403 * ttm_bo_eviction_valuable 404 * 405 * @bo: The buffer object to evict 406 * @place: the placement we need to make room for 407 * 408 * Check if it is valuable to evict the BO to make room for the given placement. 409 */ 410bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, 411 const struct ttm_place *place); 412 413/** 414 * ttm_bo_acc_size 415 * 416 * @bdev: Pointer to a ttm_bo_device struct. 417 * @bo_size: size of the buffer object in byte. 418 * @struct_size: size of the structure holding buffer object datas 419 * 420 * Returns size to account for a buffer object 421 */ 422size_t ttm_bo_acc_size(struct ttm_bo_device *bdev, 423 unsigned long bo_size, 424 unsigned struct_size); 425size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, 426 unsigned long bo_size, 427 unsigned struct_size); 428 429/** 430 * ttm_bo_init_reserved 431 * 432 * @bdev: Pointer to a ttm_bo_device struct. 433 * @bo: Pointer to a ttm_buffer_object to be initialized. 434 * @size: Requested size of buffer object. 435 * @type: Requested type of buffer object. 436 * @flags: Initial placement flags. 437 * @page_alignment: Data alignment in pages. 438 * @ctx: TTM operation context for memory allocation. 439 * @acc_size: Accounted size for this object. 440 * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one. 441 * @destroy: Destroy function. Use NULL for kfree(). 442 * 443 * This function initializes a pre-allocated struct ttm_buffer_object. 444 * As this object may be part of a larger structure, this function, 445 * together with the @destroy function, 446 * enables driver-specific objects derived from a ttm_buffer_object. 447 * 448 * On successful return, the caller owns an object kref to @bo. The kref and 449 * list_kref are usually set to 1, but note that in some situations, other 450 * tasks may already be holding references to @bo as well. 451 * Furthermore, if resv == NULL, the buffer's reservation lock will be held, 452 * and it is the caller's responsibility to call ttm_bo_unreserve. 453 * 454 * If a failure occurs, the function will call the @destroy function, or 455 * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is 456 * illegal and will likely cause memory corruption. 457 * 458 * Returns 459 * -ENOMEM: Out of memory. 460 * -EINVAL: Invalid placement flags. 461 * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources. 462 */ 463 464int ttm_bo_init_reserved(struct ttm_bo_device *bdev, 465 struct ttm_buffer_object *bo, 466 unsigned long size, 467 enum ttm_bo_type type, 468 struct ttm_placement *placement, 469 uint32_t page_alignment, 470 struct ttm_operation_ctx *ctx, 471 size_t acc_size, 472 struct sg_table *sg, 473 struct dma_resv *resv, 474 void (*destroy) (struct ttm_buffer_object *)); 475 476/** 477 * ttm_bo_init 478 * 479 * @bdev: Pointer to a ttm_bo_device struct. 480 * @bo: Pointer to a ttm_buffer_object to be initialized. 481 * @size: Requested size of buffer object. 482 * @type: Requested type of buffer object. 483 * @flags: Initial placement flags. 484 * @page_alignment: Data alignment in pages. 485 * @interruptible: If needing to sleep to wait for GPU resources, 486 * sleep interruptible. 487 * pinned in physical memory. If this behaviour is not desired, this member 488 * holds a pointer to a persistent shmem object. Typically, this would 489 * point to the shmem object backing a GEM object if TTM is used to back a 490 * GEM user interface. 491 * @acc_size: Accounted size for this object. 492 * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one. 493 * @destroy: Destroy function. Use NULL for kfree(). 494 * 495 * This function initializes a pre-allocated struct ttm_buffer_object. 496 * As this object may be part of a larger structure, this function, 497 * together with the @destroy function, 498 * enables driver-specific objects derived from a ttm_buffer_object. 499 * 500 * On successful return, the caller owns an object kref to @bo. The kref and 501 * list_kref are usually set to 1, but note that in some situations, other 502 * tasks may already be holding references to @bo as well. 503 * 504 * If a failure occurs, the function will call the @destroy function, or 505 * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is 506 * illegal and will likely cause memory corruption. 507 * 508 * Returns 509 * -ENOMEM: Out of memory. 510 * -EINVAL: Invalid placement flags. 511 * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources. 512 */ 513int ttm_bo_init(struct ttm_bo_device *bdev, struct ttm_buffer_object *bo, 514 unsigned long size, enum ttm_bo_type type, 515 struct ttm_placement *placement, 516 uint32_t page_alignment, bool interrubtible, size_t acc_size, 517 struct sg_table *sg, struct dma_resv *resv, 518 void (*destroy) (struct ttm_buffer_object *)); 519 520/** 521 * ttm_bo_create 522 * 523 * @bdev: Pointer to a ttm_bo_device struct. 524 * @size: Requested size of buffer object. 525 * @type: Requested type of buffer object. 526 * @placement: Initial placement. 527 * @page_alignment: Data alignment in pages. 528 * @interruptible: If needing to sleep while waiting for GPU resources, 529 * sleep interruptible. 530 * @p_bo: On successful completion *p_bo points to the created object. 531 * 532 * This function allocates a ttm_buffer_object, and then calls ttm_bo_init 533 * on that object. The destroy function is set to kfree(). 534 * Returns 535 * -ENOMEM: Out of memory. 536 * -EINVAL: Invalid placement flags. 537 * -ERESTARTSYS: Interrupted by signal while waiting for resources. 538 */ 539int ttm_bo_create(struct ttm_bo_device *bdev, unsigned long size, 540 enum ttm_bo_type type, struct ttm_placement *placement, 541 uint32_t page_alignment, bool interruptible, 542 struct ttm_buffer_object **p_bo); 543 544/** 545 * ttm_bo_init_mm 546 * 547 * @bdev: Pointer to a ttm_bo_device struct. 548 * @mem_type: The memory type. 549 * @p_size: size managed area in pages. 550 * 551 * Initialize a manager for a given memory type. 552 * Note: if part of driver firstopen, it must be protected from a 553 * potentially racing lastclose. 554 * Returns: 555 * -EINVAL: invalid size or memory type. 556 * -ENOMEM: Not enough memory. 557 * May also return driver-specified errors. 558 */ 559int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type, 560 unsigned long p_size); 561 562/** 563 * ttm_bo_clean_mm 564 * 565 * @bdev: Pointer to a ttm_bo_device struct. 566 * @mem_type: The memory type. 567 * 568 * Take down a manager for a given memory type after first walking 569 * the LRU list to evict any buffers left alive. 570 * 571 * Normally, this function is part of lastclose() or unload(), and at that 572 * point there shouldn't be any buffers left created by user-space, since 573 * there should've been removed by the file descriptor release() method. 574 * However, before this function is run, make sure to signal all sync objects, 575 * and verify that the delayed delete queue is empty. The driver must also 576 * make sure that there are no NO_EVICT buffers present in this memory type 577 * when the call is made. 578 * 579 * If this function is part of a VT switch, the caller must make sure that 580 * there are no appications currently validating buffers before this 581 * function is called. The caller can do that by first taking the 582 * struct ttm_bo_device::ttm_lock in write mode. 583 * 584 * Returns: 585 * -EINVAL: invalid or uninitialized memory type. 586 * -EBUSY: There are still buffers left in this memory type. 587 */ 588int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type); 589 590/** 591 * ttm_bo_evict_mm 592 * 593 * @bdev: Pointer to a ttm_bo_device struct. 594 * @mem_type: The memory type. 595 * 596 * Evicts all buffers on the lru list of the memory type. 597 * This is normally part of a VT switch or an 598 * out-of-memory-space-due-to-fragmentation handler. 599 * The caller must make sure that there are no other processes 600 * currently validating buffers, and can do that by taking the 601 * struct ttm_bo_device::ttm_lock in write mode. 602 * 603 * Returns: 604 * -EINVAL: Invalid or uninitialized memory type. 605 * -ERESTARTSYS: The call was interrupted by a signal while waiting to 606 * evict a buffer. 607 */ 608int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type); 609 610/** 611 * ttm_kmap_obj_virtual 612 * 613 * @map: A struct ttm_bo_kmap_obj returned from ttm_bo_kmap. 614 * @is_iomem: Pointer to an integer that on return indicates 1 if the 615 * virtual map is io memory, 0 if normal memory. 616 * 617 * Returns the virtual address of a buffer object area mapped by ttm_bo_kmap. 618 * If *is_iomem is 1 on return, the virtual address points to an io memory area, 619 * that should strictly be accessed by the iowriteXX() and similar functions. 620 */ 621static inline void *ttm_kmap_obj_virtual(struct ttm_bo_kmap_obj *map, 622 bool *is_iomem) 623{ 624 *is_iomem = !!(map->bo_kmap_type & TTM_BO_MAP_IOMEM_MASK); 625 return map->virtual; 626} 627 628/** 629 * ttm_bo_kmap 630 * 631 * @bo: The buffer object. 632 * @start_page: The first page to map. 633 * @num_pages: Number of pages to map. 634 * @map: pointer to a struct ttm_bo_kmap_obj representing the map. 635 * 636 * Sets up a kernel virtual mapping, using ioremap, vmap or kmap to the 637 * data in the buffer object. The ttm_kmap_obj_virtual function can then be 638 * used to obtain a virtual address to the data. 639 * 640 * Returns 641 * -ENOMEM: Out of memory. 642 * -EINVAL: Invalid range. 643 */ 644int ttm_bo_kmap(struct ttm_buffer_object *bo, unsigned long start_page, 645 unsigned long num_pages, struct ttm_bo_kmap_obj *map); 646 647/** 648 * ttm_bo_kunmap 649 * 650 * @map: Object describing the map to unmap. 651 * 652 * Unmaps a kernel map set up by ttm_bo_kmap. 653 */ 654void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map); 655 656/** 657 * ttm_bo_mmap_obj - mmap memory backed by a ttm buffer object. 658 * 659 * @vma: vma as input from the fbdev mmap method. 660 * @bo: The bo backing the address space. 661 * 662 * Maps a buffer object. 663 */ 664int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo); 665 666/** 667 * ttm_bo_mmap - mmap out of the ttm device address space. 668 * 669 * @filp: filp as input from the mmap method. 670 * @vma: vma as input from the mmap method. 671 * @bdev: Pointer to the ttm_bo_device with the address space manager. 672 * 673 * This function is intended to be called by the device mmap method. 674 * if the device address space is to be backed by the bo manager. 675 */ 676int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma, 677 struct ttm_bo_device *bdev); 678 679void *ttm_kmap_atomic_prot(struct page *page, pgprot_t prot); 680 681void ttm_kunmap_atomic_prot(void *addr, pgprot_t prot); 682 683/** 684 * ttm_bo_io 685 * 686 * @bdev: Pointer to the struct ttm_bo_device. 687 * @filp: Pointer to the struct file attempting to read / write. 688 * @wbuf: User-space pointer to address of buffer to write. NULL on read. 689 * @rbuf: User-space pointer to address of buffer to read into. 690 * Null on write. 691 * @count: Number of bytes to read / write. 692 * @f_pos: Pointer to current file position. 693 * @write: 1 for read, 0 for write. 694 * 695 * This function implements read / write into ttm buffer objects, and is 696 * intended to 697 * be called from the fops::read and fops::write method. 698 * Returns: 699 * See man (2) write, man(2) read. In particular, 700 * the function may return -ERESTARTSYS if 701 * interrupted by a signal. 702 */ 703ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp, 704 const char __user *wbuf, char __user *rbuf, 705 size_t count, loff_t *f_pos, bool write); 706 707int ttm_bo_swapout(struct ttm_bo_global *glob, 708 struct ttm_operation_ctx *ctx); 709void ttm_bo_swapout_all(struct ttm_bo_device *bdev); 710int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo); 711 712/** 713 * ttm_bo_uses_embedded_gem_object - check if the given bo uses the 714 * embedded drm_gem_object. 715 * 716 * Most ttm drivers are using gem too, so the embedded 717 * ttm_buffer_object.base will be initialized by the driver (before 718 * calling ttm_bo_init). It is also possible to use ttm without gem 719 * though (vmwgfx does that). 720 * 721 * This helper will figure whenever a given ttm bo is a gem object too 722 * or not. 723 * 724 * @bo: The bo to check. 725 */ 726static inline bool ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object *bo) 727{ 728 return bo->base.dev != NULL; 729} 730 731/* Default number of pre-faulted pages in the TTM fault handler */ 732#define TTM_BO_VM_NUM_PREFAULT 16 733 734vm_fault_t ttm_bo_vm_reserve(struct ttm_buffer_object *bo, 735 struct vm_fault *vmf); 736 737vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf, 738 pgprot_t prot, 739 pgoff_t num_prefault); 740 741void ttm_bo_vm_open(struct vm_area_struct *vma); 742 743void ttm_bo_vm_close(struct vm_area_struct *vma); 744#endif 745