Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
ttm_bo_driver.h File Reference
#include <ttm/ttm_bo_api.h>
#include <ttm/ttm_memory.h>
#include <ttm/ttm_module.h>
#include <drm/drm_mm.h>
#include <drm/drm_global.h>
#include <linux/workqueue.h>
#include <linux/fs.h>
#include <linux/spinlock.h>

Go to the source code of this file.

Data Structures

struct  ttm_backend_func
 
struct  ttm_tt
 
struct  ttm_dma_tt
 
struct  ttm_mem_type_manager_func
 
struct  ttm_mem_type_manager
 
struct  ttm_bo_driver
 
struct  ttm_bo_global_ref
 
struct  ttm_bo_global
 
struct  ttm_bo_device
 

Macros

#define TTM_PAGE_FLAG_WRITE   (1 << 3)
 
#define TTM_PAGE_FLAG_SWAPPED   (1 << 4)
 
#define TTM_PAGE_FLAG_PERSISTENT_SWAP   (1 << 5)
 
#define TTM_PAGE_FLAG_ZERO_ALLOC   (1 << 6)
 
#define TTM_PAGE_FLAG_DMA32   (1 << 7)
 
#define TTM_PAGE_FLAG_SG   (1 << 8)
 
#define TTM_MEMTYPE_FLAG_FIXED   (1 << 0) /* Fixed (on-card) PCI memory */
 
#define TTM_MEMTYPE_FLAG_MAPPABLE   (1 << 1) /* Memory mappable */
 
#define TTM_MEMTYPE_FLAG_CMA   (1 << 3) /* Can't map aperture */
 
#define TTM_NUM_MEM_TYPES   8
 
#define TTM_BO_PRIV_FLAG_MOVING
 
#define TTM_BO_PRIV_FLAG_MAX   1
 

Enumerations

enum  ttm_caching_state { tt_uncached, tt_wc, tt_cached }
 

Functions

int ttm_tt_init (struct ttm_tt *ttm, struct ttm_bo_device *bdev, unsigned long size, uint32_t page_flags, struct page *dummy_read_page)
 
int ttm_dma_tt_init (struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev, unsigned long size, uint32_t page_flags, struct page *dummy_read_page)
 
void ttm_tt_fini (struct ttm_tt *ttm)
 
void ttm_dma_tt_fini (struct ttm_dma_tt *ttm_dma)
 
int ttm_tt_bind (struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
 
void ttm_tt_destroy (struct ttm_tt *ttm)
 
void ttm_tt_unbind (struct ttm_tt *ttm)
 
int ttm_tt_swapin (struct ttm_tt *ttm)
 
void ttm_tt_cache_flush (struct page *pages[], unsigned long num_pages)
 
int ttm_tt_set_placement_caching (struct ttm_tt *ttm, uint32_t placement)
 
int ttm_tt_swapout (struct ttm_tt *ttm, struct file *persistent_swap_storage)
 
bool ttm_mem_reg_is_pci (struct ttm_bo_device *bdev, struct ttm_mem_reg *mem)
 
int ttm_bo_mem_space (struct ttm_buffer_object *bo, struct ttm_placement *placement, struct ttm_mem_reg *mem, bool interruptible, bool no_wait_reserve, bool no_wait_gpu)
 
void ttm_bo_mem_put (struct ttm_buffer_object *bo, struct ttm_mem_reg *mem)
 
void ttm_bo_mem_put_locked (struct ttm_buffer_object *bo, struct ttm_mem_reg *mem)
 
int ttm_bo_wait_cpu (struct ttm_buffer_object *bo, bool no_wait)
 
void ttm_bo_global_release (struct drm_global_reference *ref)
 
int ttm_bo_global_init (struct drm_global_reference *ref)
 
int ttm_bo_device_release (struct ttm_bo_device *bdev)
 
int ttm_bo_device_init (struct ttm_bo_device *bdev, struct ttm_bo_global *glob, struct ttm_bo_driver *driver, uint64_t file_page_offset, bool need_dma32)
 
void ttm_bo_unmap_virtual (struct ttm_buffer_object *bo)
 
void ttm_bo_unmap_virtual_locked (struct ttm_buffer_object *bo)
 
int ttm_mem_io_reserve_vm (struct ttm_buffer_object *bo)
 
void ttm_mem_io_free_vm (struct ttm_buffer_object *bo)
 
int ttm_mem_io_lock (struct ttm_mem_type_manager *man, bool interruptible)
 
void ttm_mem_io_unlock (struct ttm_mem_type_manager *man)
 
int ttm_bo_reserve (struct ttm_buffer_object *bo, bool interruptible, bool no_wait, bool use_sequence, uint32_t sequence)
 
int ttm_bo_reserve_locked (struct ttm_buffer_object *bo, bool interruptible, bool no_wait, bool use_sequence, uint32_t sequence)
 
void ttm_bo_unreserve (struct ttm_buffer_object *bo)
 
void ttm_bo_unreserve_locked (struct ttm_buffer_object *bo)
 
int ttm_bo_wait_unreserved (struct ttm_buffer_object *bo, bool interruptible)
 
int ttm_bo_move_ttm (struct ttm_buffer_object *bo, bool evict, bool no_wait_reserve, bool no_wait_gpu, struct ttm_mem_reg *new_mem)
 
int ttm_bo_move_memcpy (struct ttm_buffer_object *bo, bool evict, bool no_wait_reserve, bool no_wait_gpu, struct ttm_mem_reg *new_mem)
 
void ttm_bo_free_old_node (struct ttm_buffer_object *bo)
 
int ttm_bo_move_accel_cleanup (struct ttm_buffer_object *bo, void *sync_obj, void *sync_obj_arg, bool evict, bool no_wait_reserve, bool no_wait_gpu, struct ttm_mem_reg *new_mem)
 
pgprot_t ttm_io_prot (uint32_t caching_flags, pgprot_t tmp)
 

Variables

struct ttm_mem_type_manager_func ttm_bo_manager_func
 

Macro Definition Documentation

#define TTM_BO_PRIV_FLAG_MAX   1

Definition at line 511 of file ttm_bo_driver.h.

#define TTM_BO_PRIV_FLAG_MOVING
Value:
0 /* Buffer object is moving and needs
idling before CPU mapping */

Definition at line 510 of file ttm_bo_driver.h.

#define TTM_MEMTYPE_FLAG_CMA   (1 << 3) /* Can't map aperture */

Definition at line 148 of file ttm_bo_driver.h.

#define TTM_MEMTYPE_FLAG_FIXED   (1 << 0) /* Fixed (on-card) PCI memory */

Definition at line 146 of file ttm_bo_driver.h.

#define TTM_MEMTYPE_FLAG_MAPPABLE   (1 << 1) /* Memory mappable */

Definition at line 147 of file ttm_bo_driver.h.

#define TTM_NUM_MEM_TYPES   8

Definition at line 508 of file ttm_bo_driver.h.

#define TTM_PAGE_FLAG_DMA32   (1 << 7)

Definition at line 81 of file ttm_bo_driver.h.

#define TTM_PAGE_FLAG_PERSISTENT_SWAP   (1 << 5)

Definition at line 79 of file ttm_bo_driver.h.

#define TTM_PAGE_FLAG_SG   (1 << 8)

Definition at line 82 of file ttm_bo_driver.h.

#define TTM_PAGE_FLAG_SWAPPED   (1 << 4)

Definition at line 78 of file ttm_bo_driver.h.

#define TTM_PAGE_FLAG_WRITE   (1 << 3)

Definition at line 77 of file ttm_bo_driver.h.

#define TTM_PAGE_FLAG_ZERO_ALLOC   (1 << 6)

Definition at line 80 of file ttm_bo_driver.h.

Enumeration Type Documentation

Enumerator:
tt_uncached 
tt_wc 
tt_cached 

Definition at line 84 of file ttm_bo_driver.h.

Function Documentation

int ttm_bo_device_init ( struct ttm_bo_device bdev,
struct ttm_bo_global glob,
struct ttm_bo_driver driver,
uint64_t  file_page_offset,
bool  need_dma32 
)

ttm_bo_device_init

: A pointer to a struct ttm_bo_device to initialize. : A pointer to an initialized struct ttm_bo_global. : A pointer to a struct ttm_bo_driver set up by the caller. : Offset into the device address space that is available for buffer data. This ensures compatibility with other users of the address space.

Initializes a struct ttm_bo_device: Returns: !0: Failure.

Definition at line 1553 of file ttm_bo.c.

int ttm_bo_device_release ( struct ttm_bo_device bdev)

Definition at line 1507 of file ttm_bo.c.

void ttm_bo_free_old_node ( struct ttm_buffer_object bo)

ttm_bo_free_old_node

: A pointer to a struct ttm_buffer_object.

Utility function to free an old placement after a successful move.

Definition at line 40 of file ttm_bo_util.c.

int ttm_bo_global_init ( struct drm_global_reference ref)

Definition at line 1464 of file ttm_bo.c.

void ttm_bo_global_release ( struct drm_global_reference ref)

Definition at line 1455 of file ttm_bo.c.

void ttm_bo_mem_put ( struct ttm_buffer_object bo,
struct ttm_mem_reg mem 
)

Definition at line 856 of file ttm_bo.c.

void ttm_bo_mem_put_locked ( struct ttm_buffer_object bo,
struct ttm_mem_reg mem 
)
int ttm_bo_mem_space ( struct ttm_buffer_object bo,
struct ttm_placement placement,
struct ttm_mem_reg mem,
bool  interruptible,
bool  no_wait_reserve,
bool  no_wait_gpu 
)

ttm_bo_mem_space

: Pointer to a struct ttm_buffer_object. the data of which we want to allocate space for. : Proposed new placement for the buffer object. : A struct ttm_mem_reg. : Sleep interruptible when sliping. : Return immediately if other buffers are busy. : Return immediately if the GPU is busy.

Allocate memory space for the buffer object pointed to by , using the placement flags in , potentially evicting other idle buffer objects. This function may sleep while waiting for space to become available. Returns: -EBUSY: No space available (only if no_wait == 1). -ENOMEM: Could not allocate memory for the buffer object, either due to fragmentation or concurrent allocators. -ERESTARTSYS: An interruptible sleep was interrupted by a signal.

Creates space for memory region according to its type.

This function first searches for free space in compatible memory types in the priority order defined by the driver. If free space isn't found, then ttm_bo_mem_force_space is attempted in priority order to evict and find space.

Definition at line 950 of file ttm_bo.c.

int ttm_bo_move_accel_cleanup ( struct ttm_buffer_object bo,
void sync_obj,
void sync_obj_arg,
bool  evict,
bool  no_wait_reserve,
bool  no_wait_gpu,
struct ttm_mem_reg new_mem 
)

ttm_bo_move_accel_cleanup.

: A pointer to a struct ttm_buffer_object. : A sync object that signals when moving is complete. : An argument to pass to the sync object idle / wait functions. : This is an evict move. Don't return until the buffer is idle. : Return immediately if other buffers are busy. : Return immediately if the GPU is busy. : struct ttm_mem_reg indicating where to move.

Accelerated move function to be called when an accelerated move has been scheduled. The function will create a new temporary buffer object representing the old placement, and put the sync object on both buffer objects. After that the newly created buffer object is unref'd to be destroyed when the move is complete. This will help pipeline buffer moves.

This should help pipeline ordinary buffer moves.

Hang old buffer memory on a new buffer object, and leave it to be released when the GPU operation has completed.

If we're not moving to fixed memory, the TTM object needs to stay alive. Otherwhise hang it on the ghost bo to be unbound and destroyed.

Definition at line 612 of file ttm_bo_util.c.

int ttm_bo_move_memcpy ( struct ttm_buffer_object bo,
bool  evict,
bool  no_wait_reserve,
bool  no_wait_gpu,
struct ttm_mem_reg new_mem 
)

ttm_bo_move_memcpy

: A pointer to a struct ttm_buffer_object. : 1: This is an eviction. Don't try to pipeline. : Return immediately if other buffers are busy. : Return immediately if the GPU is busy. : struct ttm_mem_reg indicating where to move.

Fallback move function for a mappable buffer object in mappable memory. The function will, if successful, free any old aperture space, and set ()->mm_node to NULL, and update the ()->mem placement flags. If unsuccessful, the old data remains untouched, and it's up to the caller to free the memory space indicated by . Returns: !0: Failure.

Definition at line 316 of file ttm_bo_util.c.

int ttm_bo_move_ttm ( struct ttm_buffer_object bo,
bool  evict,
bool  no_wait_reserve,
bool  no_wait_gpu,
struct ttm_mem_reg new_mem 
)

ttm_bo_move_ttm

: A pointer to a struct ttm_buffer_object. : 1: This is an eviction. Don't try to pipeline. : Return immediately if other buffers are busy. : Return immediately if the GPU is busy. : struct ttm_mem_reg indicating where to move.

Optimized move function for a buffer object with both old and new placement backed by a TTM. The function will, if successful, free any old aperture space, and set ()->mm_node to NULL, and update the ()->mem placement flags. If unsuccessful, the old data remains untouched, and it's up to the caller to free the memory space indicated by . Returns: !0: Failure.

Definition at line 45 of file ttm_bo_util.c.

int ttm_bo_reserve ( struct ttm_buffer_object bo,
bool  interruptible,
bool  no_wait,
bool  use_sequence,
uint32_t  sequence 
)

ttm_bo_reserve:

: A pointer to a struct ttm_buffer_object. : Sleep interruptible if waiting. : Don't sleep while trying to reserve, rather return -EBUSY. : If is already reserved, Only sleep waiting for it to become unreserved if < ()->sequence.

Locks a buffer object for validation. (Or prevents other processes from locking it for validation) and removes it from lru lists, while taking a number of measures to prevent deadlocks.

Deadlocks may occur when two processes try to reserve multiple buffers in different order, either by will or as a result of a buffer being evicted to make room for a buffer already reserved. (Buffers are reserved before they are evicted). The following algorithm prevents such deadlocks from occurring: 1) Buffers are reserved with the lru spinlock held. Upon successful reservation they are removed from the lru list. This stops a reserved buffer from being evicted. However the lru spinlock is released between the time a buffer is selected for eviction and the time it is reserved. Therefore a check is made when a buffer is reserved for eviction, that it is still the first buffer in the lru list, before it is removed from the list. == 1 forces this check. If it fails, the function returns -EINVAL, and the caller should then choose a new buffer to evict and repeat the procedure. 2) Processes attempting to reserve multiple buffers other than for eviction, (typically execbuf), should first obtain a unique 32-bit validation sequence number, and call this function with == 1 and == the unique sequence number. If upon call of this function, the buffer object is already reserved, the validation sequence is checked against the validation sequence of the process currently reserving the buffer, and if the current validation sequence is greater than that of the process holding the reservation, the function returns -EAGAIN. Otherwise it sleeps waiting for the buffer to become unreserved, after which it retries reserving. The caller should, when receiving an -EAGAIN error release all its buffer reservations, wait for to become unreserved, and then rerun the validation with the same validation sequence. This procedure will always guarantee that the process with the lowest validation sequence will eventually succeed, preventing both deadlocks and starvation.

Returns: -EAGAIN: The reservation may cause a deadlock. Release all buffer reservations, wait for to become unreserved and try again. (only if use_sequence == 1). -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by a signal. Release all buffer reservations and return to user-space. -EBUSY: The function needed to sleep, but was true -EDEADLK: Bo already reserved using . This error code will only be returned if is set to true.

Definition at line 283 of file ttm_bo.c.

int ttm_bo_reserve_locked ( struct ttm_buffer_object bo,
bool  interruptible,
bool  no_wait,
bool  use_sequence,
uint32_t  sequence 
)

ttm_bo_reserve_locked:

: A pointer to a struct ttm_buffer_object. : Sleep interruptible if waiting. : Don't sleep while trying to reserve, rather return -EBUSY. : If is already reserved, Only sleep waiting for it to become unreserved if < ()->sequence.

Must be called with struct ttm_bo_global::lru_lock held, and will not remove reserved buffers from the lru lists. The function may release the LRU spinlock if it needs to sleep. Otherwise identical to ttm_bo_reserve.

Returns: -EAGAIN: The reservation may cause a deadlock. Release all buffer reservations, wait for to become unreserved and try again. (only if use_sequence == 1). -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by a signal. Release all buffer reservations and return to user-space. -EBUSY: The function needed to sleep, but was true -EDEADLK: Bo already reserved using . This error code will only be returned if is set to true.

Deadlock avoidance for multi-bo reserving.

We've already reserved this one.

Already reserved by a thread that will not back off for us. We need to back off.

Wake up waiters that may need to recheck for deadlock, if we decreased the sequence number.

Definition at line 216 of file ttm_bo.c.

void ttm_bo_unmap_virtual ( struct ttm_buffer_object bo)

ttm_bo_unmap_virtual

: tear down the virtual mappings for this BO

Definition at line 1632 of file ttm_bo.c.

void ttm_bo_unmap_virtual_locked ( struct ttm_buffer_object bo)

ttm_bo_unmap_virtual

: tear down the virtual mappings for this BO

The caller must take ttm_mem_io_lock before calling this function.

Definition at line 1620 of file ttm_bo.c.

void ttm_bo_unreserve ( struct ttm_buffer_object bo)

ttm_bo_unreserve

: A pointer to a struct ttm_buffer_object.

Unreserve a previous reservation of .

Definition at line 310 of file ttm_bo.c.

void ttm_bo_unreserve_locked ( struct ttm_buffer_object bo)

ttm_bo_unreserve_locked

: A pointer to a struct ttm_buffer_object.

Unreserve a previous reservation of . Needs to be called with struct ttm_bo_global::lru_lock held.

Definition at line 303 of file ttm_bo.c.

int ttm_bo_wait_cpu ( struct ttm_buffer_object bo,
bool  no_wait 
)

ttm_bo_wait_for_cpu

: Pointer to a struct ttm_buffer_object. : Don't sleep while waiting.

Wait until a buffer object is no longer sync'ed for CPU access. Returns: -EBUSY: Buffer object was sync'ed for CPU access. (only if no_wait == 1). -ERESTARTSYS: An interruptible sleep was interrupted by a signal.

Definition at line 1057 of file ttm_bo.c.

int ttm_bo_wait_unreserved ( struct ttm_buffer_object bo,
bool  interruptible 
)

ttm_bo_wait_unreserved

: A pointer to a struct ttm_buffer_object.

Wait for a struct ttm_buffer_object to become unreserved. This is typically used in the execbuf code to relax cpu-usage when a potential deadlock condition backoff.

Definition at line 161 of file ttm_bo.c.

void ttm_dma_tt_fini ( struct ttm_dma_tt ttm_dma)

Definition at line 241 of file ttm_tt.c.

int ttm_dma_tt_init ( struct ttm_dma_tt ttm_dma,
struct ttm_bo_device bdev,
unsigned long  size,
uint32_t  page_flags,
struct page dummy_read_page 
)

Definition at line 215 of file ttm_tt.c.

pgprot_t ttm_io_prot ( uint32_t  caching_flags,
pgprot_t  tmp 
)

ttm_io_prot

: Caching state. : Page protection flag for a normal, cached mapping.

Utility function that returns the pgprot_t that should be used for setting up a PTE with the caching model indicated by .

Definition at line 454 of file ttm_bo_util.c.

void ttm_mem_io_free_vm ( struct ttm_buffer_object bo)

Definition at line 173 of file ttm_bo_util.c.

int ttm_mem_io_lock ( struct ttm_mem_type_manager man,
bool  interruptible 
)

Definition at line 78 of file ttm_bo_util.c.

int ttm_mem_io_reserve_vm ( struct ttm_buffer_object bo)

Definition at line 153 of file ttm_bo_util.c.

void ttm_mem_io_unlock ( struct ttm_mem_type_manager man)

Definition at line 90 of file ttm_bo_util.c.

bool ttm_mem_reg_is_pci ( struct ttm_bo_device bdev,
struct ttm_mem_reg mem 
)

ttm_mem_reg_is_pci

: Pointer to a struct ttm_bo_device. : A valid struct ttm_mem_reg.

Returns true if the memory described by is PCI memory, false otherwise.

Definition at line 1603 of file ttm_bo.c.

int ttm_tt_bind ( struct ttm_tt ttm,
struct ttm_mem_reg bo_mem 
)

ttm_ttm_bind:

: The struct ttm_tt containing backing pages. : The struct ttm_mem_reg identifying the binding location.

Bind the pages of to an aperture location identified by

Definition at line 263 of file ttm_tt.c.

void ttm_tt_cache_flush ( struct page pages[],
unsigned long  num_pages 
)

ttm_tt_cache_flush:

: An array of pointers to struct page:s to flush. : Number of pages to flush.

Flush the data of the indicated pages from the cpu caches. This is used when changing caching attributes of the pages from cache-coherent.

void ttm_tt_destroy ( struct ttm_tt ttm)

ttm_ttm_destroy:

: The struct ttm_tt.

Unbind, unpopulate and destroy common struct ttm_tt.

Definition at line 164 of file ttm_tt.c.

void ttm_tt_fini ( struct ttm_tt ttm)

ttm_tt_fini

: the ttm_tt structure.

Free memory of ttm_tt structure

Definition at line 208 of file ttm_tt.c.

int ttm_tt_init ( struct ttm_tt ttm,
struct ttm_bo_device bdev,
unsigned long  size,
uint32_t  page_flags,
struct page dummy_read_page 
)

ttm_tt_init

: The struct ttm_tt. : pointer to a struct ttm_bo_device: : Size of the data needed backing. : Page flags as identified by TTM_PAGE_FLAG_XX flags. : See struct ttm_bo_device.

Create a struct ttm_tt to back data with system memory pages. No pages are actually allocated. Returns: NULL: Out of memory.

Definition at line 185 of file ttm_tt.c.

int ttm_tt_set_placement_caching ( struct ttm_tt ttm,
uint32_t  placement 
)

ttm_tt_set_placement_caching:

A struct ttm_tt the backing pages of which will change caching policy. : Flag indicating the desired caching policy.

This function will change caching policy of any default kernel mappings of the pages backing . If changing from cached to uncached or write-combined, all CPU caches will first be flushed to make sure the data of the pages hit RAM. This function may be very costly as it involves global TLB and cache flushes and potential page splitting / combining.

Definition at line 149 of file ttm_tt.c.

int ttm_tt_swapin ( struct ttm_tt ttm)

ttm_tt_swapin:

: The struct ttm_tt.

Swap in a previously swap out ttm_tt.

Definition at line 287 of file ttm_tt.c.

int ttm_tt_swapout ( struct ttm_tt ttm,
struct file persistent_swap_storage 
)

Definition at line 325 of file ttm_tt.c.

void ttm_tt_unbind ( struct ttm_tt ttm)

ttm_ttm_unbind:

: The struct ttm_tt.

Unbind a struct ttm_tt.

Definition at line 252 of file ttm_tt.c.

Variable Documentation

struct ttm_mem_type_manager_func ttm_bo_manager_func

Definition at line 150 of file ttm_bo_manager.c.