18c2ecf20Sopenharmony_ci/**************************************************************************
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
48c2ecf20Sopenharmony_ci * All Rights Reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
78c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the
88c2ecf20Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
98c2ecf20Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
108c2ecf20Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
118c2ecf20Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
128c2ecf20Sopenharmony_ci * the following conditions:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the
158c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
168c2ecf20Sopenharmony_ci * of the Software.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
198c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
208c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
218c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
228c2ecf20Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
238c2ecf20Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
248c2ecf20Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci **************************************************************************/
278c2ecf20Sopenharmony_ci/*
288c2ecf20Sopenharmony_ci * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
298c2ecf20Sopenharmony_ci */
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#ifndef _TTM_BO_API_H_
328c2ecf20Sopenharmony_ci#define _TTM_BO_API_H_
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include <drm/drm_gem.h>
358c2ecf20Sopenharmony_ci#include <drm/drm_hashtab.h>
368c2ecf20Sopenharmony_ci#include <drm/drm_vma_manager.h>
378c2ecf20Sopenharmony_ci#include <linux/kref.h>
388c2ecf20Sopenharmony_ci#include <linux/list.h>
398c2ecf20Sopenharmony_ci#include <linux/wait.h>
408c2ecf20Sopenharmony_ci#include <linux/mutex.h>
418c2ecf20Sopenharmony_ci#include <linux/mm.h>
428c2ecf20Sopenharmony_ci#include <linux/bitmap.h>
438c2ecf20Sopenharmony_ci#include <linux/dma-resv.h>
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#include "ttm_resource.h"
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistruct ttm_bo_global;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistruct ttm_bo_device;
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistruct drm_mm_node;
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistruct ttm_placement;
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistruct ttm_place;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistruct ttm_lru_bulk_move;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/**
608c2ecf20Sopenharmony_ci * enum ttm_bo_type
618c2ecf20Sopenharmony_ci *
628c2ecf20Sopenharmony_ci * @ttm_bo_type_device:	These are 'normal' buffers that can
638c2ecf20Sopenharmony_ci * be mmapped by user space. Each of these bos occupy a slot in the
648c2ecf20Sopenharmony_ci * device address space, that can be used for normal vm operations.
658c2ecf20Sopenharmony_ci *
668c2ecf20Sopenharmony_ci * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers,
678c2ecf20Sopenharmony_ci * but they cannot be accessed from user-space. For kernel-only use.
688c2ecf20Sopenharmony_ci *
698c2ecf20Sopenharmony_ci * @ttm_bo_type_sg: Buffer made from dmabuf sg table shared with another
708c2ecf20Sopenharmony_ci * driver.
718c2ecf20Sopenharmony_ci */
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cienum ttm_bo_type {
748c2ecf20Sopenharmony_ci	ttm_bo_type_device,
758c2ecf20Sopenharmony_ci	ttm_bo_type_kernel,
768c2ecf20Sopenharmony_ci	ttm_bo_type_sg
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistruct ttm_tt;
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/**
828c2ecf20Sopenharmony_ci * struct ttm_buffer_object
838c2ecf20Sopenharmony_ci *
848c2ecf20Sopenharmony_ci * @base: drm_gem_object superclass data.
858c2ecf20Sopenharmony_ci * @bdev: Pointer to the buffer object device structure.
868c2ecf20Sopenharmony_ci * @type: The bo type.
878c2ecf20Sopenharmony_ci * @destroy: Destruction function. If NULL, kfree is used.
888c2ecf20Sopenharmony_ci * @num_pages: Actual number of pages.
898c2ecf20Sopenharmony_ci * @acc_size: Accounted size for this object.
908c2ecf20Sopenharmony_ci * @kref: Reference count of this buffer object. When this refcount reaches
918c2ecf20Sopenharmony_ci * zero, the object is destroyed or put on the delayed delete list.
928c2ecf20Sopenharmony_ci * @mem: structure describing current placement.
938c2ecf20Sopenharmony_ci * @persistent_swap_storage: Usually the swap storage is deleted for buffers
948c2ecf20Sopenharmony_ci * pinned in physical memory. If this behaviour is not desired, this member
958c2ecf20Sopenharmony_ci * holds a pointer to a persistent shmem object.
968c2ecf20Sopenharmony_ci * @ttm: TTM structure holding system pages.
978c2ecf20Sopenharmony_ci * @evicted: Whether the object was evicted without user-space knowing.
988c2ecf20Sopenharmony_ci * @deleted: True if the object is only a zombie and already deleted.
998c2ecf20Sopenharmony_ci * @lru: List head for the lru list.
1008c2ecf20Sopenharmony_ci * @ddestroy: List head for the delayed destroy list.
1018c2ecf20Sopenharmony_ci * @swap: List head for swap LRU list.
1028c2ecf20Sopenharmony_ci * @moving: Fence set when BO is moving
1038c2ecf20Sopenharmony_ci * @offset: The current GPU offset, which can have different meanings
1048c2ecf20Sopenharmony_ci * depending on the memory type. For SYSTEM type memory, it should be 0.
1058c2ecf20Sopenharmony_ci * @cur_placement: Hint of current placement.
1068c2ecf20Sopenharmony_ci *
1078c2ecf20Sopenharmony_ci * Base class for TTM buffer object, that deals with data placement and CPU
1088c2ecf20Sopenharmony_ci * mappings. GPU mappings are really up to the driver, but for simpler GPUs
1098c2ecf20Sopenharmony_ci * the driver can usually use the placement offset @offset directly as the
1108c2ecf20Sopenharmony_ci * GPU virtual address. For drivers implementing multiple
1118c2ecf20Sopenharmony_ci * GPU memory manager contexts, the driver should manage the address space
1128c2ecf20Sopenharmony_ci * in these contexts separately and use these objects to get the correct
1138c2ecf20Sopenharmony_ci * placement and caching for these GPU maps. This makes it possible to use
1148c2ecf20Sopenharmony_ci * these objects for even quite elaborate memory management schemes.
1158c2ecf20Sopenharmony_ci * The destroy member, the API visibility of this object makes it possible
1168c2ecf20Sopenharmony_ci * to derive driver specific types.
1178c2ecf20Sopenharmony_ci */
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_cistruct ttm_buffer_object {
1208c2ecf20Sopenharmony_ci	struct drm_gem_object base;
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	/**
1238c2ecf20Sopenharmony_ci	 * Members constant at init.
1248c2ecf20Sopenharmony_ci	 */
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	struct ttm_bo_device *bdev;
1278c2ecf20Sopenharmony_ci	enum ttm_bo_type type;
1288c2ecf20Sopenharmony_ci	void (*destroy) (struct ttm_buffer_object *);
1298c2ecf20Sopenharmony_ci	unsigned long num_pages;
1308c2ecf20Sopenharmony_ci	size_t acc_size;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	/**
1338c2ecf20Sopenharmony_ci	* Members not needing protection.
1348c2ecf20Sopenharmony_ci	*/
1358c2ecf20Sopenharmony_ci	struct kref kref;
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	/**
1388c2ecf20Sopenharmony_ci	 * Members protected by the bo::resv::reserved lock.
1398c2ecf20Sopenharmony_ci	 */
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	struct ttm_resource mem;
1428c2ecf20Sopenharmony_ci	struct file *persistent_swap_storage;
1438c2ecf20Sopenharmony_ci	struct ttm_tt *ttm;
1448c2ecf20Sopenharmony_ci	bool deleted;
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	/**
1478c2ecf20Sopenharmony_ci	 * Members protected by the bdev::lru_lock.
1488c2ecf20Sopenharmony_ci	 */
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	struct list_head lru;
1518c2ecf20Sopenharmony_ci	struct list_head ddestroy;
1528c2ecf20Sopenharmony_ci	struct list_head swap;
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	/**
1558c2ecf20Sopenharmony_ci	 * Members protected by a bo reservation.
1568c2ecf20Sopenharmony_ci	 */
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci	struct dma_fence *moving;
1598c2ecf20Sopenharmony_ci	unsigned priority;
1608c2ecf20Sopenharmony_ci	unsigned pin_count;
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	/**
1638c2ecf20Sopenharmony_ci	 * Special members that are protected by the reserve lock
1648c2ecf20Sopenharmony_ci	 * and the bo::lock when written to. Can be read with
1658c2ecf20Sopenharmony_ci	 * either of these locks held.
1668c2ecf20Sopenharmony_ci	 */
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	struct sg_table *sg;
1698c2ecf20Sopenharmony_ci};
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/**
1728c2ecf20Sopenharmony_ci * struct ttm_bo_kmap_obj
1738c2ecf20Sopenharmony_ci *
1748c2ecf20Sopenharmony_ci * @virtual: The current kernel virtual address.
1758c2ecf20Sopenharmony_ci * @page: The page when kmap'ing a single page.
1768c2ecf20Sopenharmony_ci * @bo_kmap_type: Type of bo_kmap.
1778c2ecf20Sopenharmony_ci *
1788c2ecf20Sopenharmony_ci * Object describing a kernel mapping. Since a TTM bo may be located
1798c2ecf20Sopenharmony_ci * in various memory types with various caching policies, the
1808c2ecf20Sopenharmony_ci * mapping can either be an ioremap, a vmap, a kmap or part of a
1818c2ecf20Sopenharmony_ci * premapped region.
1828c2ecf20Sopenharmony_ci */
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci#define TTM_BO_MAP_IOMEM_MASK 0x80
1858c2ecf20Sopenharmony_cistruct ttm_bo_kmap_obj {
1868c2ecf20Sopenharmony_ci	void *virtual;
1878c2ecf20Sopenharmony_ci	struct page *page;
1888c2ecf20Sopenharmony_ci	enum {
1898c2ecf20Sopenharmony_ci		ttm_bo_map_iomap        = 1 | TTM_BO_MAP_IOMEM_MASK,
1908c2ecf20Sopenharmony_ci		ttm_bo_map_vmap         = 2,
1918c2ecf20Sopenharmony_ci		ttm_bo_map_kmap         = 3,
1928c2ecf20Sopenharmony_ci		ttm_bo_map_premapped    = 4 | TTM_BO_MAP_IOMEM_MASK,
1938c2ecf20Sopenharmony_ci	} bo_kmap_type;
1948c2ecf20Sopenharmony_ci	struct ttm_buffer_object *bo;
1958c2ecf20Sopenharmony_ci};
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci/**
1988c2ecf20Sopenharmony_ci * struct ttm_operation_ctx
1998c2ecf20Sopenharmony_ci *
2008c2ecf20Sopenharmony_ci * @interruptible: Sleep interruptible if sleeping.
2018c2ecf20Sopenharmony_ci * @no_wait_gpu: Return immediately if the GPU is busy.
2028c2ecf20Sopenharmony_ci * @resv: Reservation object to allow reserved evictions with.
2038c2ecf20Sopenharmony_ci * @flags: Including the following flags
2048c2ecf20Sopenharmony_ci *
2058c2ecf20Sopenharmony_ci * Context for TTM operations like changing buffer placement or general memory
2068c2ecf20Sopenharmony_ci * allocation.
2078c2ecf20Sopenharmony_ci */
2088c2ecf20Sopenharmony_cistruct ttm_operation_ctx {
2098c2ecf20Sopenharmony_ci	bool interruptible;
2108c2ecf20Sopenharmony_ci	bool no_wait_gpu;
2118c2ecf20Sopenharmony_ci	struct dma_resv *resv;
2128c2ecf20Sopenharmony_ci	uint64_t bytes_moved;
2138c2ecf20Sopenharmony_ci	uint32_t flags;
2148c2ecf20Sopenharmony_ci};
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci/* Allow eviction of reserved BOs */
2178c2ecf20Sopenharmony_ci#define TTM_OPT_FLAG_ALLOW_RES_EVICT		0x1
2188c2ecf20Sopenharmony_ci/* when serving page fault or suspend, allow alloc anyway */
2198c2ecf20Sopenharmony_ci#define TTM_OPT_FLAG_FORCE_ALLOC		0x2
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci/**
2228c2ecf20Sopenharmony_ci * ttm_bo_get - reference a struct ttm_buffer_object
2238c2ecf20Sopenharmony_ci *
2248c2ecf20Sopenharmony_ci * @bo: The buffer object.
2258c2ecf20Sopenharmony_ci */
2268c2ecf20Sopenharmony_cistatic inline void ttm_bo_get(struct ttm_buffer_object *bo)
2278c2ecf20Sopenharmony_ci{
2288c2ecf20Sopenharmony_ci	kref_get(&bo->kref);
2298c2ecf20Sopenharmony_ci}
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci/**
2328c2ecf20Sopenharmony_ci * ttm_bo_get_unless_zero - reference a struct ttm_buffer_object unless
2338c2ecf20Sopenharmony_ci * its refcount has already reached zero.
2348c2ecf20Sopenharmony_ci * @bo: The buffer object.
2358c2ecf20Sopenharmony_ci *
2368c2ecf20Sopenharmony_ci * Used to reference a TTM buffer object in lookups where the object is removed
2378c2ecf20Sopenharmony_ci * from the lookup structure during the destructor and for RCU lookups.
2388c2ecf20Sopenharmony_ci *
2398c2ecf20Sopenharmony_ci * Returns: @bo if the referencing was successful, NULL otherwise.
2408c2ecf20Sopenharmony_ci */
2418c2ecf20Sopenharmony_cistatic inline __must_check struct ttm_buffer_object *
2428c2ecf20Sopenharmony_cittm_bo_get_unless_zero(struct ttm_buffer_object *bo)
2438c2ecf20Sopenharmony_ci{
2448c2ecf20Sopenharmony_ci	if (!kref_get_unless_zero(&bo->kref))
2458c2ecf20Sopenharmony_ci		return NULL;
2468c2ecf20Sopenharmony_ci	return bo;
2478c2ecf20Sopenharmony_ci}
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci/**
2508c2ecf20Sopenharmony_ci * ttm_bo_wait - wait for buffer idle.
2518c2ecf20Sopenharmony_ci *
2528c2ecf20Sopenharmony_ci * @bo:  The buffer object.
2538c2ecf20Sopenharmony_ci * @interruptible:  Use interruptible wait.
2548c2ecf20Sopenharmony_ci * @no_wait:  Return immediately if buffer is busy.
2558c2ecf20Sopenharmony_ci *
2568c2ecf20Sopenharmony_ci * This function must be called with the bo::mutex held, and makes
2578c2ecf20Sopenharmony_ci * sure any previous rendering to the buffer is completed.
2588c2ecf20Sopenharmony_ci * Note: It might be necessary to block validations before the
2598c2ecf20Sopenharmony_ci * wait by reserving the buffer.
2608c2ecf20Sopenharmony_ci * Returns -EBUSY if no_wait is true and the buffer is busy.
2618c2ecf20Sopenharmony_ci * Returns -ERESTARTSYS if interrupted by a signal.
2628c2ecf20Sopenharmony_ci */
2638c2ecf20Sopenharmony_ciint ttm_bo_wait(struct ttm_buffer_object *bo, bool interruptible, bool no_wait);
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci/**
2668c2ecf20Sopenharmony_ci * ttm_bo_mem_compat - Check if proposed placement is compatible with a bo
2678c2ecf20Sopenharmony_ci *
2688c2ecf20Sopenharmony_ci * @placement:  Return immediately if buffer is busy.
2698c2ecf20Sopenharmony_ci * @mem:  The struct ttm_resource indicating the region where the bo resides
2708c2ecf20Sopenharmony_ci * @new_flags: Describes compatible placement found
2718c2ecf20Sopenharmony_ci *
2728c2ecf20Sopenharmony_ci * Returns true if the placement is compatible
2738c2ecf20Sopenharmony_ci */
2748c2ecf20Sopenharmony_cibool ttm_bo_mem_compat(struct ttm_placement *placement, struct ttm_resource *mem,
2758c2ecf20Sopenharmony_ci		       uint32_t *new_flags);
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci/**
2788c2ecf20Sopenharmony_ci * ttm_bo_validate
2798c2ecf20Sopenharmony_ci *
2808c2ecf20Sopenharmony_ci * @bo: The buffer object.
2818c2ecf20Sopenharmony_ci * @placement: Proposed placement for the buffer object.
2828c2ecf20Sopenharmony_ci * @ctx: validation parameters.
2838c2ecf20Sopenharmony_ci *
2848c2ecf20Sopenharmony_ci * Changes placement and caching policy of the buffer object
2858c2ecf20Sopenharmony_ci * according proposed placement.
2868c2ecf20Sopenharmony_ci * Returns
2878c2ecf20Sopenharmony_ci * -EINVAL on invalid proposed placement.
2888c2ecf20Sopenharmony_ci * -ENOMEM on out-of-memory condition.
2898c2ecf20Sopenharmony_ci * -EBUSY if no_wait is true and buffer busy.
2908c2ecf20Sopenharmony_ci * -ERESTARTSYS if interrupted by a signal.
2918c2ecf20Sopenharmony_ci */
2928c2ecf20Sopenharmony_ciint ttm_bo_validate(struct ttm_buffer_object *bo,
2938c2ecf20Sopenharmony_ci		    struct ttm_placement *placement,
2948c2ecf20Sopenharmony_ci		    struct ttm_operation_ctx *ctx);
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci/**
2978c2ecf20Sopenharmony_ci * ttm_bo_put
2988c2ecf20Sopenharmony_ci *
2998c2ecf20Sopenharmony_ci * @bo: The buffer object.
3008c2ecf20Sopenharmony_ci *
3018c2ecf20Sopenharmony_ci * Unreference a buffer object.
3028c2ecf20Sopenharmony_ci */
3038c2ecf20Sopenharmony_civoid ttm_bo_put(struct ttm_buffer_object *bo);
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci/**
3068c2ecf20Sopenharmony_ci * ttm_bo_move_to_lru_tail
3078c2ecf20Sopenharmony_ci *
3088c2ecf20Sopenharmony_ci * @bo: The buffer object.
3098c2ecf20Sopenharmony_ci * @bulk: optional bulk move structure to remember BO positions
3108c2ecf20Sopenharmony_ci *
3118c2ecf20Sopenharmony_ci * Move this BO to the tail of all lru lists used to lookup and reserve an
3128c2ecf20Sopenharmony_ci * object. This function must be called with struct ttm_bo_global::lru_lock
3138c2ecf20Sopenharmony_ci * held, and is used to make a BO less likely to be considered for eviction.
3148c2ecf20Sopenharmony_ci */
3158c2ecf20Sopenharmony_civoid ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo,
3168c2ecf20Sopenharmony_ci			     struct ttm_lru_bulk_move *bulk);
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci/**
3198c2ecf20Sopenharmony_ci * ttm_bo_bulk_move_lru_tail
3208c2ecf20Sopenharmony_ci *
3218c2ecf20Sopenharmony_ci * @bulk: bulk move structure
3228c2ecf20Sopenharmony_ci *
3238c2ecf20Sopenharmony_ci * Bulk move BOs to the LRU tail, only valid to use when driver makes sure that
3248c2ecf20Sopenharmony_ci * BO order never changes. Should be called with ttm_bo_global::lru_lock held.
3258c2ecf20Sopenharmony_ci */
3268c2ecf20Sopenharmony_civoid ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk);
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci/**
3298c2ecf20Sopenharmony_ci * ttm_bo_lock_delayed_workqueue
3308c2ecf20Sopenharmony_ci *
3318c2ecf20Sopenharmony_ci * Prevent the delayed workqueue from running.
3328c2ecf20Sopenharmony_ci * Returns
3338c2ecf20Sopenharmony_ci * True if the workqueue was queued at the time
3348c2ecf20Sopenharmony_ci */
3358c2ecf20Sopenharmony_ciint ttm_bo_lock_delayed_workqueue(struct ttm_bo_device *bdev);
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci/**
3388c2ecf20Sopenharmony_ci * ttm_bo_unlock_delayed_workqueue
3398c2ecf20Sopenharmony_ci *
3408c2ecf20Sopenharmony_ci * Allows the delayed workqueue to run.
3418c2ecf20Sopenharmony_ci */
3428c2ecf20Sopenharmony_civoid ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev, int resched);
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci/**
3458c2ecf20Sopenharmony_ci * ttm_bo_eviction_valuable
3468c2ecf20Sopenharmony_ci *
3478c2ecf20Sopenharmony_ci * @bo: The buffer object to evict
3488c2ecf20Sopenharmony_ci * @place: the placement we need to make room for
3498c2ecf20Sopenharmony_ci *
3508c2ecf20Sopenharmony_ci * Check if it is valuable to evict the BO to make room for the given placement.
3518c2ecf20Sopenharmony_ci */
3528c2ecf20Sopenharmony_cibool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
3538c2ecf20Sopenharmony_ci			      const struct ttm_place *place);
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_cisize_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev,
3568c2ecf20Sopenharmony_ci			   unsigned long bo_size,
3578c2ecf20Sopenharmony_ci			   unsigned struct_size);
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci/**
3608c2ecf20Sopenharmony_ci * ttm_bo_init_reserved
3618c2ecf20Sopenharmony_ci *
3628c2ecf20Sopenharmony_ci * @bdev: Pointer to a ttm_bo_device struct.
3638c2ecf20Sopenharmony_ci * @bo: Pointer to a ttm_buffer_object to be initialized.
3648c2ecf20Sopenharmony_ci * @size: Requested size of buffer object.
3658c2ecf20Sopenharmony_ci * @type: Requested type of buffer object.
3668c2ecf20Sopenharmony_ci * @flags: Initial placement flags.
3678c2ecf20Sopenharmony_ci * @page_alignment: Data alignment in pages.
3688c2ecf20Sopenharmony_ci * @ctx: TTM operation context for memory allocation.
3698c2ecf20Sopenharmony_ci * @acc_size: Accounted size for this object.
3708c2ecf20Sopenharmony_ci * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
3718c2ecf20Sopenharmony_ci * @destroy: Destroy function. Use NULL for kfree().
3728c2ecf20Sopenharmony_ci *
3738c2ecf20Sopenharmony_ci * This function initializes a pre-allocated struct ttm_buffer_object.
3748c2ecf20Sopenharmony_ci * As this object may be part of a larger structure, this function,
3758c2ecf20Sopenharmony_ci * together with the @destroy function,
3768c2ecf20Sopenharmony_ci * enables driver-specific objects derived from a ttm_buffer_object.
3778c2ecf20Sopenharmony_ci *
3788c2ecf20Sopenharmony_ci * On successful return, the caller owns an object kref to @bo. The kref and
3798c2ecf20Sopenharmony_ci * list_kref are usually set to 1, but note that in some situations, other
3808c2ecf20Sopenharmony_ci * tasks may already be holding references to @bo as well.
3818c2ecf20Sopenharmony_ci * Furthermore, if resv == NULL, the buffer's reservation lock will be held,
3828c2ecf20Sopenharmony_ci * and it is the caller's responsibility to call ttm_bo_unreserve.
3838c2ecf20Sopenharmony_ci *
3848c2ecf20Sopenharmony_ci * If a failure occurs, the function will call the @destroy function, or
3858c2ecf20Sopenharmony_ci * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
3868c2ecf20Sopenharmony_ci * illegal and will likely cause memory corruption.
3878c2ecf20Sopenharmony_ci *
3888c2ecf20Sopenharmony_ci * Returns
3898c2ecf20Sopenharmony_ci * -ENOMEM: Out of memory.
3908c2ecf20Sopenharmony_ci * -EINVAL: Invalid placement flags.
3918c2ecf20Sopenharmony_ci * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
3928c2ecf20Sopenharmony_ci */
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ciint ttm_bo_init_reserved(struct ttm_bo_device *bdev,
3958c2ecf20Sopenharmony_ci			 struct ttm_buffer_object *bo,
3968c2ecf20Sopenharmony_ci			 unsigned long size,
3978c2ecf20Sopenharmony_ci			 enum ttm_bo_type type,
3988c2ecf20Sopenharmony_ci			 struct ttm_placement *placement,
3998c2ecf20Sopenharmony_ci			 uint32_t page_alignment,
4008c2ecf20Sopenharmony_ci			 struct ttm_operation_ctx *ctx,
4018c2ecf20Sopenharmony_ci			 size_t acc_size,
4028c2ecf20Sopenharmony_ci			 struct sg_table *sg,
4038c2ecf20Sopenharmony_ci			 struct dma_resv *resv,
4048c2ecf20Sopenharmony_ci			 void (*destroy) (struct ttm_buffer_object *));
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci/**
4078c2ecf20Sopenharmony_ci * ttm_bo_init
4088c2ecf20Sopenharmony_ci *
4098c2ecf20Sopenharmony_ci * @bdev: Pointer to a ttm_bo_device struct.
4108c2ecf20Sopenharmony_ci * @bo: Pointer to a ttm_buffer_object to be initialized.
4118c2ecf20Sopenharmony_ci * @size: Requested size of buffer object.
4128c2ecf20Sopenharmony_ci * @type: Requested type of buffer object.
4138c2ecf20Sopenharmony_ci * @flags: Initial placement flags.
4148c2ecf20Sopenharmony_ci * @page_alignment: Data alignment in pages.
4158c2ecf20Sopenharmony_ci * @interruptible: If needing to sleep to wait for GPU resources,
4168c2ecf20Sopenharmony_ci * sleep interruptible.
4178c2ecf20Sopenharmony_ci * pinned in physical memory. If this behaviour is not desired, this member
4188c2ecf20Sopenharmony_ci * holds a pointer to a persistent shmem object. Typically, this would
4198c2ecf20Sopenharmony_ci * point to the shmem object backing a GEM object if TTM is used to back a
4208c2ecf20Sopenharmony_ci * GEM user interface.
4218c2ecf20Sopenharmony_ci * @acc_size: Accounted size for this object.
4228c2ecf20Sopenharmony_ci * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
4238c2ecf20Sopenharmony_ci * @destroy: Destroy function. Use NULL for kfree().
4248c2ecf20Sopenharmony_ci *
4258c2ecf20Sopenharmony_ci * This function initializes a pre-allocated struct ttm_buffer_object.
4268c2ecf20Sopenharmony_ci * As this object may be part of a larger structure, this function,
4278c2ecf20Sopenharmony_ci * together with the @destroy function,
4288c2ecf20Sopenharmony_ci * enables driver-specific objects derived from a ttm_buffer_object.
4298c2ecf20Sopenharmony_ci *
4308c2ecf20Sopenharmony_ci * On successful return, the caller owns an object kref to @bo. The kref and
4318c2ecf20Sopenharmony_ci * list_kref are usually set to 1, but note that in some situations, other
4328c2ecf20Sopenharmony_ci * tasks may already be holding references to @bo as well.
4338c2ecf20Sopenharmony_ci *
4348c2ecf20Sopenharmony_ci * If a failure occurs, the function will call the @destroy function, or
4358c2ecf20Sopenharmony_ci * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
4368c2ecf20Sopenharmony_ci * illegal and will likely cause memory corruption.
4378c2ecf20Sopenharmony_ci *
4388c2ecf20Sopenharmony_ci * Returns
4398c2ecf20Sopenharmony_ci * -ENOMEM: Out of memory.
4408c2ecf20Sopenharmony_ci * -EINVAL: Invalid placement flags.
4418c2ecf20Sopenharmony_ci * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
4428c2ecf20Sopenharmony_ci */
4438c2ecf20Sopenharmony_ciint ttm_bo_init(struct ttm_bo_device *bdev, struct ttm_buffer_object *bo,
4448c2ecf20Sopenharmony_ci		unsigned long size, enum ttm_bo_type type,
4458c2ecf20Sopenharmony_ci		struct ttm_placement *placement,
4468c2ecf20Sopenharmony_ci		uint32_t page_alignment, bool interrubtible, size_t acc_size,
4478c2ecf20Sopenharmony_ci		struct sg_table *sg, struct dma_resv *resv,
4488c2ecf20Sopenharmony_ci		void (*destroy) (struct ttm_buffer_object *));
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci/**
4518c2ecf20Sopenharmony_ci * ttm_bo_create
4528c2ecf20Sopenharmony_ci *
4538c2ecf20Sopenharmony_ci * @bdev: Pointer to a ttm_bo_device struct.
4548c2ecf20Sopenharmony_ci * @size: Requested size of buffer object.
4558c2ecf20Sopenharmony_ci * @type: Requested type of buffer object.
4568c2ecf20Sopenharmony_ci * @placement: Initial placement.
4578c2ecf20Sopenharmony_ci * @page_alignment: Data alignment in pages.
4588c2ecf20Sopenharmony_ci * @interruptible: If needing to sleep while waiting for GPU resources,
4598c2ecf20Sopenharmony_ci * sleep interruptible.
4608c2ecf20Sopenharmony_ci * @p_bo: On successful completion *p_bo points to the created object.
4618c2ecf20Sopenharmony_ci *
4628c2ecf20Sopenharmony_ci * This function allocates a ttm_buffer_object, and then calls ttm_bo_init
4638c2ecf20Sopenharmony_ci * on that object. The destroy function is set to kfree().
4648c2ecf20Sopenharmony_ci * Returns
4658c2ecf20Sopenharmony_ci * -ENOMEM: Out of memory.
4668c2ecf20Sopenharmony_ci * -EINVAL: Invalid placement flags.
4678c2ecf20Sopenharmony_ci * -ERESTARTSYS: Interrupted by signal while waiting for resources.
4688c2ecf20Sopenharmony_ci */
4698c2ecf20Sopenharmony_ciint ttm_bo_create(struct ttm_bo_device *bdev, unsigned long size,
4708c2ecf20Sopenharmony_ci		  enum ttm_bo_type type, struct ttm_placement *placement,
4718c2ecf20Sopenharmony_ci		  uint32_t page_alignment, bool interruptible,
4728c2ecf20Sopenharmony_ci		  struct ttm_buffer_object **p_bo);
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci/**
4758c2ecf20Sopenharmony_ci * ttm_bo_evict_mm
4768c2ecf20Sopenharmony_ci *
4778c2ecf20Sopenharmony_ci * @bdev: Pointer to a ttm_bo_device struct.
4788c2ecf20Sopenharmony_ci * @mem_type: The memory type.
4798c2ecf20Sopenharmony_ci *
4808c2ecf20Sopenharmony_ci * Evicts all buffers on the lru list of the memory type.
4818c2ecf20Sopenharmony_ci * This is normally part of a VT switch or an
4828c2ecf20Sopenharmony_ci * out-of-memory-space-due-to-fragmentation handler.
4838c2ecf20Sopenharmony_ci * The caller must make sure that there are no other processes
4848c2ecf20Sopenharmony_ci * currently validating buffers, and can do that by taking the
4858c2ecf20Sopenharmony_ci * struct ttm_bo_device::ttm_lock in write mode.
4868c2ecf20Sopenharmony_ci *
4878c2ecf20Sopenharmony_ci * Returns:
4888c2ecf20Sopenharmony_ci * -EINVAL: Invalid or uninitialized memory type.
4898c2ecf20Sopenharmony_ci * -ERESTARTSYS: The call was interrupted by a signal while waiting to
4908c2ecf20Sopenharmony_ci * evict a buffer.
4918c2ecf20Sopenharmony_ci */
4928c2ecf20Sopenharmony_ciint ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type);
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci/**
4958c2ecf20Sopenharmony_ci * ttm_kmap_obj_virtual
4968c2ecf20Sopenharmony_ci *
4978c2ecf20Sopenharmony_ci * @map: A struct ttm_bo_kmap_obj returned from ttm_bo_kmap.
4988c2ecf20Sopenharmony_ci * @is_iomem: Pointer to an integer that on return indicates 1 if the
4998c2ecf20Sopenharmony_ci * virtual map is io memory, 0 if normal memory.
5008c2ecf20Sopenharmony_ci *
5018c2ecf20Sopenharmony_ci * Returns the virtual address of a buffer object area mapped by ttm_bo_kmap.
5028c2ecf20Sopenharmony_ci * If *is_iomem is 1 on return, the virtual address points to an io memory area,
5038c2ecf20Sopenharmony_ci * that should strictly be accessed by the iowriteXX() and similar functions.
5048c2ecf20Sopenharmony_ci */
5058c2ecf20Sopenharmony_cistatic inline void *ttm_kmap_obj_virtual(struct ttm_bo_kmap_obj *map,
5068c2ecf20Sopenharmony_ci					 bool *is_iomem)
5078c2ecf20Sopenharmony_ci{
5088c2ecf20Sopenharmony_ci	*is_iomem = !!(map->bo_kmap_type & TTM_BO_MAP_IOMEM_MASK);
5098c2ecf20Sopenharmony_ci	return map->virtual;
5108c2ecf20Sopenharmony_ci}
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci/**
5138c2ecf20Sopenharmony_ci * ttm_bo_kmap
5148c2ecf20Sopenharmony_ci *
5158c2ecf20Sopenharmony_ci * @bo: The buffer object.
5168c2ecf20Sopenharmony_ci * @start_page: The first page to map.
5178c2ecf20Sopenharmony_ci * @num_pages: Number of pages to map.
5188c2ecf20Sopenharmony_ci * @map: pointer to a struct ttm_bo_kmap_obj representing the map.
5198c2ecf20Sopenharmony_ci *
5208c2ecf20Sopenharmony_ci * Sets up a kernel virtual mapping, using ioremap, vmap or kmap to the
5218c2ecf20Sopenharmony_ci * data in the buffer object. The ttm_kmap_obj_virtual function can then be
5228c2ecf20Sopenharmony_ci * used to obtain a virtual address to the data.
5238c2ecf20Sopenharmony_ci *
5248c2ecf20Sopenharmony_ci * Returns
5258c2ecf20Sopenharmony_ci * -ENOMEM: Out of memory.
5268c2ecf20Sopenharmony_ci * -EINVAL: Invalid range.
5278c2ecf20Sopenharmony_ci */
5288c2ecf20Sopenharmony_ciint ttm_bo_kmap(struct ttm_buffer_object *bo, unsigned long start_page,
5298c2ecf20Sopenharmony_ci		unsigned long num_pages, struct ttm_bo_kmap_obj *map);
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_ci/**
5328c2ecf20Sopenharmony_ci * ttm_bo_kunmap
5338c2ecf20Sopenharmony_ci *
5348c2ecf20Sopenharmony_ci * @map: Object describing the map to unmap.
5358c2ecf20Sopenharmony_ci *
5368c2ecf20Sopenharmony_ci * Unmaps a kernel map set up by ttm_bo_kmap.
5378c2ecf20Sopenharmony_ci */
5388c2ecf20Sopenharmony_civoid ttm_bo_kunmap(struct ttm_bo_kmap_obj *map);
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_ci/**
5418c2ecf20Sopenharmony_ci * ttm_bo_mmap_obj - mmap memory backed by a ttm buffer object.
5428c2ecf20Sopenharmony_ci *
5438c2ecf20Sopenharmony_ci * @vma:       vma as input from the fbdev mmap method.
5448c2ecf20Sopenharmony_ci * @bo:        The bo backing the address space.
5458c2ecf20Sopenharmony_ci *
5468c2ecf20Sopenharmony_ci * Maps a buffer object.
5478c2ecf20Sopenharmony_ci */
5488c2ecf20Sopenharmony_ciint ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo);
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci/**
5518c2ecf20Sopenharmony_ci * ttm_bo_mmap - mmap out of the ttm device address space.
5528c2ecf20Sopenharmony_ci *
5538c2ecf20Sopenharmony_ci * @filp:      filp as input from the mmap method.
5548c2ecf20Sopenharmony_ci * @vma:       vma as input from the mmap method.
5558c2ecf20Sopenharmony_ci * @bdev:      Pointer to the ttm_bo_device with the address space manager.
5568c2ecf20Sopenharmony_ci *
5578c2ecf20Sopenharmony_ci * This function is intended to be called by the device mmap method.
5588c2ecf20Sopenharmony_ci * if the device address space is to be backed by the bo manager.
5598c2ecf20Sopenharmony_ci */
5608c2ecf20Sopenharmony_ciint ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
5618c2ecf20Sopenharmony_ci		struct ttm_bo_device *bdev);
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_ci/**
5648c2ecf20Sopenharmony_ci * ttm_bo_io
5658c2ecf20Sopenharmony_ci *
5668c2ecf20Sopenharmony_ci * @bdev:      Pointer to the struct ttm_bo_device.
5678c2ecf20Sopenharmony_ci * @filp:      Pointer to the struct file attempting to read / write.
5688c2ecf20Sopenharmony_ci * @wbuf:      User-space pointer to address of buffer to write. NULL on read.
5698c2ecf20Sopenharmony_ci * @rbuf:      User-space pointer to address of buffer to read into.
5708c2ecf20Sopenharmony_ci * Null on write.
5718c2ecf20Sopenharmony_ci * @count:     Number of bytes to read / write.
5728c2ecf20Sopenharmony_ci * @f_pos:     Pointer to current file position.
5738c2ecf20Sopenharmony_ci * @write:     1 for read, 0 for write.
5748c2ecf20Sopenharmony_ci *
5758c2ecf20Sopenharmony_ci * This function implements read / write into ttm buffer objects, and is
5768c2ecf20Sopenharmony_ci * intended to
5778c2ecf20Sopenharmony_ci * be called from the fops::read and fops::write method.
5788c2ecf20Sopenharmony_ci * Returns:
5798c2ecf20Sopenharmony_ci * See man (2) write, man(2) read. In particular,
5808c2ecf20Sopenharmony_ci * the function may return -ERESTARTSYS if
5818c2ecf20Sopenharmony_ci * interrupted by a signal.
5828c2ecf20Sopenharmony_ci */
5838c2ecf20Sopenharmony_cissize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
5848c2ecf20Sopenharmony_ci		  const char __user *wbuf, char __user *rbuf,
5858c2ecf20Sopenharmony_ci		  size_t count, loff_t *f_pos, bool write);
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ciint ttm_bo_swapout(struct ttm_bo_global *glob,
5888c2ecf20Sopenharmony_ci			struct ttm_operation_ctx *ctx);
5898c2ecf20Sopenharmony_civoid ttm_bo_swapout_all(void);
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_ci/**
5928c2ecf20Sopenharmony_ci * ttm_bo_uses_embedded_gem_object - check if the given bo uses the
5938c2ecf20Sopenharmony_ci * embedded drm_gem_object.
5948c2ecf20Sopenharmony_ci *
5958c2ecf20Sopenharmony_ci * Most ttm drivers are using gem too, so the embedded
5968c2ecf20Sopenharmony_ci * ttm_buffer_object.base will be initialized by the driver (before
5978c2ecf20Sopenharmony_ci * calling ttm_bo_init).  It is also possible to use ttm without gem
5988c2ecf20Sopenharmony_ci * though (vmwgfx does that).
5998c2ecf20Sopenharmony_ci *
6008c2ecf20Sopenharmony_ci * This helper will figure whenever a given ttm bo is a gem object too
6018c2ecf20Sopenharmony_ci * or not.
6028c2ecf20Sopenharmony_ci *
6038c2ecf20Sopenharmony_ci * @bo: The bo to check.
6048c2ecf20Sopenharmony_ci */
6058c2ecf20Sopenharmony_cistatic inline bool ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object *bo)
6068c2ecf20Sopenharmony_ci{
6078c2ecf20Sopenharmony_ci	return bo->base.dev != NULL;
6088c2ecf20Sopenharmony_ci}
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_ci/**
6118c2ecf20Sopenharmony_ci * ttm_bo_pin - Pin the buffer object.
6128c2ecf20Sopenharmony_ci * @bo: The buffer object to pin
6138c2ecf20Sopenharmony_ci *
6148c2ecf20Sopenharmony_ci * Make sure the buffer is not evicted any more during memory pressure.
6158c2ecf20Sopenharmony_ci */
6168c2ecf20Sopenharmony_cistatic inline void ttm_bo_pin(struct ttm_buffer_object *bo)
6178c2ecf20Sopenharmony_ci{
6188c2ecf20Sopenharmony_ci	dma_resv_assert_held(bo->base.resv);
6198c2ecf20Sopenharmony_ci	++bo->pin_count;
6208c2ecf20Sopenharmony_ci}
6218c2ecf20Sopenharmony_ci
6228c2ecf20Sopenharmony_ci/**
6238c2ecf20Sopenharmony_ci * ttm_bo_unpin - Unpin the buffer object.
6248c2ecf20Sopenharmony_ci * @bo: The buffer object to unpin
6258c2ecf20Sopenharmony_ci *
6268c2ecf20Sopenharmony_ci * Allows the buffer object to be evicted again during memory pressure.
6278c2ecf20Sopenharmony_ci */
6288c2ecf20Sopenharmony_cistatic inline void ttm_bo_unpin(struct ttm_buffer_object *bo)
6298c2ecf20Sopenharmony_ci{
6308c2ecf20Sopenharmony_ci	dma_resv_assert_held(bo->base.resv);
6318c2ecf20Sopenharmony_ci	if (bo->pin_count)
6328c2ecf20Sopenharmony_ci		--bo->pin_count;
6338c2ecf20Sopenharmony_ci	else
6348c2ecf20Sopenharmony_ci		WARN_ON_ONCE(true);
6358c2ecf20Sopenharmony_ci}
6368c2ecf20Sopenharmony_ci
6378c2ecf20Sopenharmony_ciint ttm_mem_evict_first(struct ttm_bo_device *bdev,
6388c2ecf20Sopenharmony_ci			struct ttm_resource_manager *man,
6398c2ecf20Sopenharmony_ci			const struct ttm_place *place,
6408c2ecf20Sopenharmony_ci			struct ttm_operation_ctx *ctx,
6418c2ecf20Sopenharmony_ci			struct ww_acquire_ctx *ticket);
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci/* Default number of pre-faulted pages in the TTM fault handler */
6448c2ecf20Sopenharmony_ci#define TTM_BO_VM_NUM_PREFAULT 16
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_civm_fault_t ttm_bo_vm_reserve(struct ttm_buffer_object *bo,
6478c2ecf20Sopenharmony_ci			     struct vm_fault *vmf);
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_civm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
6508c2ecf20Sopenharmony_ci				    pgprot_t prot,
6518c2ecf20Sopenharmony_ci				    pgoff_t num_prefault,
6528c2ecf20Sopenharmony_ci				    pgoff_t fault_page_size);
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_civm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf);
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_civoid ttm_bo_vm_open(struct vm_area_struct *vma);
6578c2ecf20Sopenharmony_ci
6588c2ecf20Sopenharmony_civoid ttm_bo_vm_close(struct vm_area_struct *vma);
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_ciint ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr,
6618c2ecf20Sopenharmony_ci		     void *buf, int len, int write);
6628c2ecf20Sopenharmony_ci
6638c2ecf20Sopenharmony_ci#endif
664