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