1eb314613SChristian König /* 2eb314613SChristian König * Copyright 2018 Advanced Micro Devices, Inc. 3eb314613SChristian König * 4eb314613SChristian König * Permission is hereby granted, free of charge, to any person obtaining a 5eb314613SChristian König * copy of this software and associated documentation files (the "Software"), 6eb314613SChristian König * to deal in the Software without restriction, including without limitation 7eb314613SChristian König * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8eb314613SChristian König * and/or sell copies of the Software, and to permit persons to whom the 9eb314613SChristian König * Software is furnished to do so, subject to the following conditions: 10eb314613SChristian König * 11eb314613SChristian König * The above copyright notice and this permission notice shall be included in 12eb314613SChristian König * all copies or substantial portions of the Software. 13eb314613SChristian König * 14eb314613SChristian König * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15eb314613SChristian König * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16eb314613SChristian König * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17eb314613SChristian König * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18eb314613SChristian König * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19eb314613SChristian König * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20eb314613SChristian König * OTHER DEALINGS IN THE SOFTWARE. 21eb314613SChristian König * 22eb314613SChristian König * 23eb314613SChristian König */ 24eb314613SChristian König 25eb314613SChristian König #ifndef _TTM_BO_INTERNAL_H_ 26eb314613SChristian König #define _TTM_BO_INTERNAL_H_ 27eb314613SChristian König 28eb314613SChristian König #include <drm/ttm/ttm_bo.h> 29eb314613SChristian König 30eb314613SChristian König /** 31*9ec1ac83SChristian König * ttm_bo_get - reference a struct ttm_buffer_object 32*9ec1ac83SChristian König * 33*9ec1ac83SChristian König * @bo: The buffer object. 34*9ec1ac83SChristian König */ 35*9ec1ac83SChristian König static inline void ttm_bo_get(struct ttm_buffer_object *bo) 36*9ec1ac83SChristian König { 37*9ec1ac83SChristian König kref_get(&bo->kref); 38*9ec1ac83SChristian König } 39*9ec1ac83SChristian König 40*9ec1ac83SChristian König /** 41eb314613SChristian König * ttm_bo_get_unless_zero - reference a struct ttm_buffer_object unless 42eb314613SChristian König * its refcount has already reached zero. 43eb314613SChristian König * @bo: The buffer object. 44eb314613SChristian König * 45eb314613SChristian König * Used to reference a TTM buffer object in lookups where the object is removed 46eb314613SChristian König * from the lookup structure during the destructor and for RCU lookups. 47eb314613SChristian König * 48eb314613SChristian König * Returns: @bo if the referencing was successful, NULL otherwise. 49eb314613SChristian König */ 50eb314613SChristian König static inline __must_check struct ttm_buffer_object * 51eb314613SChristian König ttm_bo_get_unless_zero(struct ttm_buffer_object *bo) 52eb314613SChristian König { 53eb314613SChristian König if (!kref_get_unless_zero(&bo->kref)) 54eb314613SChristian König return NULL; 55eb314613SChristian König return bo; 56eb314613SChristian König } 57eb314613SChristian König 58eb314613SChristian König #endif 59