10b8762e9SThomas Hellstrom /************************************************************************** 20b8762e9SThomas Hellstrom * 30b8762e9SThomas Hellstrom * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA 40b8762e9SThomas Hellstrom * All Rights Reserved. 50b8762e9SThomas Hellstrom * 60b8762e9SThomas Hellstrom * Permission is hereby granted, free of charge, to any person obtaining a 70b8762e9SThomas Hellstrom * copy of this software and associated documentation files (the 80b8762e9SThomas Hellstrom * "Software"), to deal in the Software without restriction, including 90b8762e9SThomas Hellstrom * without limitation the rights to use, copy, modify, merge, publish, 100b8762e9SThomas Hellstrom * distribute, sub license, and/or sell copies of the Software, and to 110b8762e9SThomas Hellstrom * permit persons to whom the Software is furnished to do so, subject to 120b8762e9SThomas Hellstrom * the following conditions: 130b8762e9SThomas Hellstrom * 140b8762e9SThomas Hellstrom * The above copyright notice and this permission notice (including the 150b8762e9SThomas Hellstrom * next paragraph) shall be included in all copies or substantial portions 160b8762e9SThomas Hellstrom * of the Software. 170b8762e9SThomas Hellstrom * 180b8762e9SThomas Hellstrom * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 190b8762e9SThomas Hellstrom * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 200b8762e9SThomas Hellstrom * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 210b8762e9SThomas Hellstrom * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 220b8762e9SThomas Hellstrom * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 230b8762e9SThomas Hellstrom * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 240b8762e9SThomas Hellstrom * USE OR OTHER DEALINGS IN THE SOFTWARE. 250b8762e9SThomas Hellstrom * 260b8762e9SThomas Hellstrom **************************************************************************/ 270b8762e9SThomas Hellstrom /* 280b8762e9SThomas Hellstrom * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> 290b8762e9SThomas Hellstrom */ 300b8762e9SThomas Hellstrom /** @file ttm_object.h 310b8762e9SThomas Hellstrom * 320b8762e9SThomas Hellstrom * Base- and reference object implementation for the various 330b8762e9SThomas Hellstrom * ttm objects. Implements reference counting, minimal security checks 340b8762e9SThomas Hellstrom * and release on file close. 350b8762e9SThomas Hellstrom */ 360b8762e9SThomas Hellstrom 370b8762e9SThomas Hellstrom #ifndef _TTM_OBJECT_H_ 380b8762e9SThomas Hellstrom #define _TTM_OBJECT_H_ 390b8762e9SThomas Hellstrom 400b8762e9SThomas Hellstrom #include <linux/list.h> 410b8762e9SThomas Hellstrom #include <drm/drm_hashtab.h> 420b8762e9SThomas Hellstrom #include <linux/kref.h> 430b8762e9SThomas Hellstrom #include <linux/rcupdate.h> 440b8762e9SThomas Hellstrom #include <linux/dma-buf.h> 450b8762e9SThomas Hellstrom #include <drm/ttm/ttm_memory.h> 460b8762e9SThomas Hellstrom 470b8762e9SThomas Hellstrom /** 480b8762e9SThomas Hellstrom * enum ttm_ref_type 490b8762e9SThomas Hellstrom * 500b8762e9SThomas Hellstrom * Describes what type of reference a ref object holds. 510b8762e9SThomas Hellstrom * 520b8762e9SThomas Hellstrom * TTM_REF_USAGE is a simple refcount on a base object. 530b8762e9SThomas Hellstrom * 540b8762e9SThomas Hellstrom * TTM_REF_SYNCCPU_READ is a SYNCCPU_READ reference on a 550b8762e9SThomas Hellstrom * buffer object. 560b8762e9SThomas Hellstrom * 570b8762e9SThomas Hellstrom * TTM_REF_SYNCCPU_WRITE is a SYNCCPU_WRITE reference on a 580b8762e9SThomas Hellstrom * buffer object. 590b8762e9SThomas Hellstrom * 600b8762e9SThomas Hellstrom */ 610b8762e9SThomas Hellstrom 620b8762e9SThomas Hellstrom enum ttm_ref_type { 630b8762e9SThomas Hellstrom TTM_REF_USAGE, 640b8762e9SThomas Hellstrom TTM_REF_SYNCCPU_READ, 650b8762e9SThomas Hellstrom TTM_REF_SYNCCPU_WRITE, 660b8762e9SThomas Hellstrom TTM_REF_NUM 670b8762e9SThomas Hellstrom }; 680b8762e9SThomas Hellstrom 690b8762e9SThomas Hellstrom /** 700b8762e9SThomas Hellstrom * enum ttm_object_type 710b8762e9SThomas Hellstrom * 720b8762e9SThomas Hellstrom * One entry per ttm object type. 730b8762e9SThomas Hellstrom * Device-specific types should use the 740b8762e9SThomas Hellstrom * ttm_driver_typex types. 750b8762e9SThomas Hellstrom */ 760b8762e9SThomas Hellstrom 770b8762e9SThomas Hellstrom enum ttm_object_type { 780b8762e9SThomas Hellstrom ttm_fence_type, 790b8762e9SThomas Hellstrom ttm_buffer_type, 800b8762e9SThomas Hellstrom ttm_lock_type, 810b8762e9SThomas Hellstrom ttm_prime_type, 820b8762e9SThomas Hellstrom ttm_driver_type0 = 256, 830b8762e9SThomas Hellstrom ttm_driver_type1, 840b8762e9SThomas Hellstrom ttm_driver_type2, 850b8762e9SThomas Hellstrom ttm_driver_type3, 860b8762e9SThomas Hellstrom ttm_driver_type4, 870b8762e9SThomas Hellstrom ttm_driver_type5 880b8762e9SThomas Hellstrom }; 890b8762e9SThomas Hellstrom 900b8762e9SThomas Hellstrom struct ttm_object_file; 910b8762e9SThomas Hellstrom struct ttm_object_device; 920b8762e9SThomas Hellstrom 930b8762e9SThomas Hellstrom /** 940b8762e9SThomas Hellstrom * struct ttm_base_object 950b8762e9SThomas Hellstrom * 960b8762e9SThomas Hellstrom * @hash: hash entry for the per-device object hash. 970b8762e9SThomas Hellstrom * @type: derived type this object is base class for. 980b8762e9SThomas Hellstrom * @shareable: Other ttm_object_files can access this object. 990b8762e9SThomas Hellstrom * 1000b8762e9SThomas Hellstrom * @tfile: Pointer to ttm_object_file of the creator. 1010b8762e9SThomas Hellstrom * NULL if the object was not created by a user request. 1020b8762e9SThomas Hellstrom * (kernel object). 1030b8762e9SThomas Hellstrom * 1040b8762e9SThomas Hellstrom * @refcount: Number of references to this object, not 1050b8762e9SThomas Hellstrom * including the hash entry. A reference to a base object can 1060b8762e9SThomas Hellstrom * only be held by a ref object. 1070b8762e9SThomas Hellstrom * 1080b8762e9SThomas Hellstrom * @refcount_release: A function to be called when there are 1090b8762e9SThomas Hellstrom * no more references to this object. This function should 1100b8762e9SThomas Hellstrom * destroy the object (or make sure destruction eventually happens), 1110b8762e9SThomas Hellstrom * and when it is called, the object has 1120b8762e9SThomas Hellstrom * already been taken out of the per-device hash. The parameter 1130b8762e9SThomas Hellstrom * "base" should be set to NULL by the function. 1140b8762e9SThomas Hellstrom * 1150b8762e9SThomas Hellstrom * @ref_obj_release: A function to be called when a reference object 1160b8762e9SThomas Hellstrom * with another ttm_ref_type than TTM_REF_USAGE is deleted. 1170b8762e9SThomas Hellstrom * This function may, for example, release a lock held by a user-space 1180b8762e9SThomas Hellstrom * process. 1190b8762e9SThomas Hellstrom * 1200b8762e9SThomas Hellstrom * This struct is intended to be used as a base struct for objects that 1210b8762e9SThomas Hellstrom * are visible to user-space. It provides a global name, race-safe 1220b8762e9SThomas Hellstrom * access and refcounting, minimal access contol and hooks for unref actions. 1230b8762e9SThomas Hellstrom */ 1240b8762e9SThomas Hellstrom 1250b8762e9SThomas Hellstrom struct ttm_base_object { 1260b8762e9SThomas Hellstrom struct rcu_head rhead; 1270b8762e9SThomas Hellstrom struct ttm_object_file *tfile; 1280b8762e9SThomas Hellstrom struct kref refcount; 1290b8762e9SThomas Hellstrom void (*refcount_release) (struct ttm_base_object **base); 1300b8762e9SThomas Hellstrom void (*ref_obj_release) (struct ttm_base_object *base, 1310b8762e9SThomas Hellstrom enum ttm_ref_type ref_type); 132c7eae626SThomas Hellstrom u32 handle; 133c7eae626SThomas Hellstrom enum ttm_object_type object_type; 134c7eae626SThomas Hellstrom u32 shareable; 1350b8762e9SThomas Hellstrom }; 1360b8762e9SThomas Hellstrom 1370b8762e9SThomas Hellstrom 1380b8762e9SThomas Hellstrom /** 1390b8762e9SThomas Hellstrom * struct ttm_prime_object - Modified base object that is prime-aware 1400b8762e9SThomas Hellstrom * 1410b8762e9SThomas Hellstrom * @base: struct ttm_base_object that we derive from 1420b8762e9SThomas Hellstrom * @mutex: Mutex protecting the @dma_buf member. 1430b8762e9SThomas Hellstrom * @size: Size of the dma_buf associated with this object 1440b8762e9SThomas Hellstrom * @real_type: Type of the underlying object. Needed since we're setting 1450b8762e9SThomas Hellstrom * the value of @base::object_type to ttm_prime_type 1460b8762e9SThomas Hellstrom * @dma_buf: Non ref-coutned pointer to a struct dma_buf created from this 1470b8762e9SThomas Hellstrom * object. 1480b8762e9SThomas Hellstrom * @refcount_release: The underlying object's release method. Needed since 1490b8762e9SThomas Hellstrom * we set @base::refcount_release to our own release method. 1500b8762e9SThomas Hellstrom */ 1510b8762e9SThomas Hellstrom 1520b8762e9SThomas Hellstrom struct ttm_prime_object { 1530b8762e9SThomas Hellstrom struct ttm_base_object base; 1540b8762e9SThomas Hellstrom struct mutex mutex; 1550b8762e9SThomas Hellstrom size_t size; 1560b8762e9SThomas Hellstrom enum ttm_object_type real_type; 1570b8762e9SThomas Hellstrom struct dma_buf *dma_buf; 1580b8762e9SThomas Hellstrom void (*refcount_release) (struct ttm_base_object **); 1590b8762e9SThomas Hellstrom }; 1600b8762e9SThomas Hellstrom 1610b8762e9SThomas Hellstrom /** 1620b8762e9SThomas Hellstrom * ttm_base_object_init 1630b8762e9SThomas Hellstrom * 1640b8762e9SThomas Hellstrom * @tfile: Pointer to a struct ttm_object_file. 1650b8762e9SThomas Hellstrom * @base: The struct ttm_base_object to initialize. 1660b8762e9SThomas Hellstrom * @shareable: This object is shareable with other applcations. 1670b8762e9SThomas Hellstrom * (different @tfile pointers.) 1680b8762e9SThomas Hellstrom * @type: The object type. 1690b8762e9SThomas Hellstrom * @refcount_release: See the struct ttm_base_object description. 1700b8762e9SThomas Hellstrom * @ref_obj_release: See the struct ttm_base_object description. 1710b8762e9SThomas Hellstrom * 1720b8762e9SThomas Hellstrom * Initializes a struct ttm_base_object. 1730b8762e9SThomas Hellstrom */ 1740b8762e9SThomas Hellstrom 1750b8762e9SThomas Hellstrom extern int ttm_base_object_init(struct ttm_object_file *tfile, 1760b8762e9SThomas Hellstrom struct ttm_base_object *base, 1770b8762e9SThomas Hellstrom bool shareable, 1780b8762e9SThomas Hellstrom enum ttm_object_type type, 1790b8762e9SThomas Hellstrom void (*refcount_release) (struct ttm_base_object 1800b8762e9SThomas Hellstrom **), 1810b8762e9SThomas Hellstrom void (*ref_obj_release) (struct ttm_base_object 1820b8762e9SThomas Hellstrom *, 1830b8762e9SThomas Hellstrom enum ttm_ref_type 1840b8762e9SThomas Hellstrom ref_type)); 1850b8762e9SThomas Hellstrom 1860b8762e9SThomas Hellstrom /** 1870b8762e9SThomas Hellstrom * ttm_base_object_lookup 1880b8762e9SThomas Hellstrom * 1890b8762e9SThomas Hellstrom * @tfile: Pointer to a struct ttm_object_file. 1900b8762e9SThomas Hellstrom * @key: Hash key 1910b8762e9SThomas Hellstrom * 1920b8762e9SThomas Hellstrom * Looks up a struct ttm_base_object with the key @key. 1930b8762e9SThomas Hellstrom */ 1940b8762e9SThomas Hellstrom 1950b8762e9SThomas Hellstrom extern struct ttm_base_object *ttm_base_object_lookup(struct ttm_object_file 1960b8762e9SThomas Hellstrom *tfile, uint32_t key); 1970b8762e9SThomas Hellstrom 1980b8762e9SThomas Hellstrom /** 1990b8762e9SThomas Hellstrom * ttm_base_object_lookup_for_ref 2000b8762e9SThomas Hellstrom * 2010b8762e9SThomas Hellstrom * @tdev: Pointer to a struct ttm_object_device. 2020b8762e9SThomas Hellstrom * @key: Hash key 2030b8762e9SThomas Hellstrom * 2040b8762e9SThomas Hellstrom * Looks up a struct ttm_base_object with the key @key. 2050b8762e9SThomas Hellstrom * This function should only be used when the struct tfile associated with the 2060b8762e9SThomas Hellstrom * caller doesn't yet have a reference to the base object. 2070b8762e9SThomas Hellstrom */ 2080b8762e9SThomas Hellstrom 2090b8762e9SThomas Hellstrom extern struct ttm_base_object * 2100b8762e9SThomas Hellstrom ttm_base_object_lookup_for_ref(struct ttm_object_device *tdev, uint32_t key); 2110b8762e9SThomas Hellstrom 2120b8762e9SThomas Hellstrom /** 2130b8762e9SThomas Hellstrom * ttm_base_object_unref 2140b8762e9SThomas Hellstrom * 2150b8762e9SThomas Hellstrom * @p_base: Pointer to a pointer referencing a struct ttm_base_object. 2160b8762e9SThomas Hellstrom * 2170b8762e9SThomas Hellstrom * Decrements the base object refcount and clears the pointer pointed to by 2180b8762e9SThomas Hellstrom * p_base. 2190b8762e9SThomas Hellstrom */ 2200b8762e9SThomas Hellstrom 2210b8762e9SThomas Hellstrom extern void ttm_base_object_unref(struct ttm_base_object **p_base); 2220b8762e9SThomas Hellstrom 2230b8762e9SThomas Hellstrom /** 2240b8762e9SThomas Hellstrom * ttm_ref_object_add. 2250b8762e9SThomas Hellstrom * 2260b8762e9SThomas Hellstrom * @tfile: A struct ttm_object_file representing the application owning the 2270b8762e9SThomas Hellstrom * ref_object. 2280b8762e9SThomas Hellstrom * @base: The base object to reference. 2290b8762e9SThomas Hellstrom * @ref_type: The type of reference. 2300b8762e9SThomas Hellstrom * @existed: Upon completion, indicates that an identical reference object 2310b8762e9SThomas Hellstrom * already existed, and the refcount was upped on that object instead. 2320b8762e9SThomas Hellstrom * @require_existed: Fail with -EPERM if an identical ref object didn't 2330b8762e9SThomas Hellstrom * already exist. 2340b8762e9SThomas Hellstrom * 2350b8762e9SThomas Hellstrom * Checks that the base object is shareable and adds a ref object to it. 2360b8762e9SThomas Hellstrom * 2370b8762e9SThomas Hellstrom * Adding a ref object to a base object is basically like referencing the 2380b8762e9SThomas Hellstrom * base object, but a user-space application holds the reference. When the 2390b8762e9SThomas Hellstrom * file corresponding to @tfile is closed, all its reference objects are 2400b8762e9SThomas Hellstrom * deleted. A reference object can have different types depending on what 2410b8762e9SThomas Hellstrom * it's intended for. It can be refcounting to prevent object destruction, 2420b8762e9SThomas Hellstrom * When user-space takes a lock, it can add a ref object to that lock to 2430b8762e9SThomas Hellstrom * make sure the lock is released if the application dies. A ref object 2440b8762e9SThomas Hellstrom * will hold a single reference on a base object. 2450b8762e9SThomas Hellstrom */ 2460b8762e9SThomas Hellstrom extern int ttm_ref_object_add(struct ttm_object_file *tfile, 2470b8762e9SThomas Hellstrom struct ttm_base_object *base, 2480b8762e9SThomas Hellstrom enum ttm_ref_type ref_type, bool *existed, 2490b8762e9SThomas Hellstrom bool require_existed); 2500b8762e9SThomas Hellstrom 2510b8762e9SThomas Hellstrom extern bool ttm_ref_object_exists(struct ttm_object_file *tfile, 2520b8762e9SThomas Hellstrom struct ttm_base_object *base); 2530b8762e9SThomas Hellstrom 2540b8762e9SThomas Hellstrom /** 2550b8762e9SThomas Hellstrom * ttm_ref_object_base_unref 2560b8762e9SThomas Hellstrom * 2570b8762e9SThomas Hellstrom * @key: Key representing the base object. 2580b8762e9SThomas Hellstrom * @ref_type: Ref type of the ref object to be dereferenced. 2590b8762e9SThomas Hellstrom * 2600b8762e9SThomas Hellstrom * Unreference a ref object with type @ref_type 2610b8762e9SThomas Hellstrom * on the base object identified by @key. If there are no duplicate 2620b8762e9SThomas Hellstrom * references, the ref object will be destroyed and the base object 2630b8762e9SThomas Hellstrom * will be unreferenced. 2640b8762e9SThomas Hellstrom */ 2650b8762e9SThomas Hellstrom extern int ttm_ref_object_base_unref(struct ttm_object_file *tfile, 2660b8762e9SThomas Hellstrom unsigned long key, 2670b8762e9SThomas Hellstrom enum ttm_ref_type ref_type); 2680b8762e9SThomas Hellstrom 2690b8762e9SThomas Hellstrom /** 2700b8762e9SThomas Hellstrom * ttm_object_file_init - initialize a struct ttm_object file 2710b8762e9SThomas Hellstrom * 2720b8762e9SThomas Hellstrom * @tdev: A struct ttm_object device this file is initialized on. 2730b8762e9SThomas Hellstrom * @hash_order: Order of the hash table used to hold the reference objects. 2740b8762e9SThomas Hellstrom * 2750b8762e9SThomas Hellstrom * This is typically called by the file_ops::open function. 2760b8762e9SThomas Hellstrom */ 2770b8762e9SThomas Hellstrom 2780b8762e9SThomas Hellstrom extern struct ttm_object_file *ttm_object_file_init(struct ttm_object_device 2790b8762e9SThomas Hellstrom *tdev, 2800b8762e9SThomas Hellstrom unsigned int hash_order); 2810b8762e9SThomas Hellstrom 2820b8762e9SThomas Hellstrom /** 2830b8762e9SThomas Hellstrom * ttm_object_file_release - release data held by a ttm_object_file 2840b8762e9SThomas Hellstrom * 2850b8762e9SThomas Hellstrom * @p_tfile: Pointer to pointer to the ttm_object_file object to release. 2860b8762e9SThomas Hellstrom * *p_tfile will be set to NULL by this function. 2870b8762e9SThomas Hellstrom * 2880b8762e9SThomas Hellstrom * Releases all data associated by a ttm_object_file. 2890b8762e9SThomas Hellstrom * Typically called from file_ops::release. The caller must 2900b8762e9SThomas Hellstrom * ensure that there are no concurrent users of tfile. 2910b8762e9SThomas Hellstrom */ 2920b8762e9SThomas Hellstrom 2930b8762e9SThomas Hellstrom extern void ttm_object_file_release(struct ttm_object_file **p_tfile); 2940b8762e9SThomas Hellstrom 2950b8762e9SThomas Hellstrom /** 2960b8762e9SThomas Hellstrom * ttm_object device init - initialize a struct ttm_object_device 2970b8762e9SThomas Hellstrom * 2980b8762e9SThomas Hellstrom * @mem_glob: struct ttm_mem_global for memory accounting. 2990b8762e9SThomas Hellstrom * @hash_order: Order of hash table used to hash the base objects. 3000b8762e9SThomas Hellstrom * @ops: DMA buf ops for prime objects of this device. 3010b8762e9SThomas Hellstrom * 3020b8762e9SThomas Hellstrom * This function is typically called on device initialization to prepare 3030b8762e9SThomas Hellstrom * data structures needed for ttm base and ref objects. 3040b8762e9SThomas Hellstrom */ 3050b8762e9SThomas Hellstrom 3060b8762e9SThomas Hellstrom extern struct ttm_object_device * 3070b8762e9SThomas Hellstrom ttm_object_device_init(struct ttm_mem_global *mem_glob, 3080b8762e9SThomas Hellstrom unsigned int hash_order, 3090b8762e9SThomas Hellstrom const struct dma_buf_ops *ops); 3100b8762e9SThomas Hellstrom 3110b8762e9SThomas Hellstrom /** 3120b8762e9SThomas Hellstrom * ttm_object_device_release - release data held by a ttm_object_device 3130b8762e9SThomas Hellstrom * 3140b8762e9SThomas Hellstrom * @p_tdev: Pointer to pointer to the ttm_object_device object to release. 3150b8762e9SThomas Hellstrom * *p_tdev will be set to NULL by this function. 3160b8762e9SThomas Hellstrom * 3170b8762e9SThomas Hellstrom * Releases all data associated by a ttm_object_device. 3180b8762e9SThomas Hellstrom * Typically called from driver::unload before the destruction of the 3190b8762e9SThomas Hellstrom * device private data structure. 3200b8762e9SThomas Hellstrom */ 3210b8762e9SThomas Hellstrom 3220b8762e9SThomas Hellstrom extern void ttm_object_device_release(struct ttm_object_device **p_tdev); 3230b8762e9SThomas Hellstrom 3240b8762e9SThomas Hellstrom #define ttm_base_object_kfree(__object, __base)\ 3250b8762e9SThomas Hellstrom kfree_rcu(__object, __base.rhead) 3260b8762e9SThomas Hellstrom 3270b8762e9SThomas Hellstrom extern int ttm_prime_object_init(struct ttm_object_file *tfile, 3280b8762e9SThomas Hellstrom size_t size, 3290b8762e9SThomas Hellstrom struct ttm_prime_object *prime, 3300b8762e9SThomas Hellstrom bool shareable, 3310b8762e9SThomas Hellstrom enum ttm_object_type type, 3320b8762e9SThomas Hellstrom void (*refcount_release) 3330b8762e9SThomas Hellstrom (struct ttm_base_object **), 3340b8762e9SThomas Hellstrom void (*ref_obj_release) 3350b8762e9SThomas Hellstrom (struct ttm_base_object *, 3360b8762e9SThomas Hellstrom enum ttm_ref_type ref_type)); 3370b8762e9SThomas Hellstrom 3380b8762e9SThomas Hellstrom static inline enum ttm_object_type 3390b8762e9SThomas Hellstrom ttm_base_object_type(struct ttm_base_object *base) 3400b8762e9SThomas Hellstrom { 3410b8762e9SThomas Hellstrom return (base->object_type == ttm_prime_type) ? 3420b8762e9SThomas Hellstrom container_of(base, struct ttm_prime_object, base)->real_type : 3430b8762e9SThomas Hellstrom base->object_type; 3440b8762e9SThomas Hellstrom } 3450b8762e9SThomas Hellstrom extern int ttm_prime_fd_to_handle(struct ttm_object_file *tfile, 3460b8762e9SThomas Hellstrom int fd, u32 *handle); 3470b8762e9SThomas Hellstrom extern int ttm_prime_handle_to_fd(struct ttm_object_file *tfile, 3480b8762e9SThomas Hellstrom uint32_t handle, uint32_t flags, 3490b8762e9SThomas Hellstrom int *prime_fd); 3500b8762e9SThomas Hellstrom 3510b8762e9SThomas Hellstrom #define ttm_prime_object_kfree(__obj, __prime) \ 3520b8762e9SThomas Hellstrom kfree_rcu(__obj, __prime.base.rhead) 353c7eae626SThomas Hellstrom 354c7eae626SThomas Hellstrom /* 355c7eae626SThomas Hellstrom * Extra memory required by the base object's idr storage, which is allocated 356c7eae626SThomas Hellstrom * separately from the base object itself. We estimate an on-average 128 bytes 357c7eae626SThomas Hellstrom * per idr. 358c7eae626SThomas Hellstrom */ 359c7eae626SThomas Hellstrom #define TTM_OBJ_EXTRA_SIZE 128 3600b8762e9SThomas Hellstrom #endif 361