Sources/ospboard/opt/osp/src/kernel/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_blk.c
/**
 * dpu_hw_blk_get - get hw_blk from free pool
 * @hw_blk: if specified, increment reference count only
 * @type: if hw_blk is not specified, allocate the next available of this type
 * @id: if specified (>= 0), allocate the given instance of the above type
 * return: pointer to hw block object
 */
get hw_blk from free pool
@hw_blk: if specified, increment reference count only
@type: if hw_blk is not specified, allocate the next available of this type
@id: if specified (>= 0), allocate the given instance of the above type
return: pointer to hw block object
get hw_blk from free pool @hw_blk : if specified increment reference count only @type : if hw_blk is not specified allocate the next available of this type @id : if specified ( > = 0 ) allocate the given instance of the above type return : pointer to hw block object
struct dpu_hw_blk *dpu_hw_blk_get(struct dpu_hw_blk *hw_blk, u32 type, int id)
{
	struct dpu_hw_blk *curr;
	int rc, refcount;
	if (!hw_blk) {
		mutex_lock(&dpu_hw_blk_lock);
		list_for_each_entry(curr, &dpu_hw_blk_list, list) {
			if ((curr->type != type) ||
					(id >= 0 && curr->id != id) ||
					(id < 0 &&
						atomic_read(&curr->refcount)))
				continue;
			hw_blk = curr;
			break;
		}
		mutex_unlock(&dpu_hw_blk_lock);
	}
	if (!hw_blk) {
		pr_debug("no hw_blk:%d\n", type);
		return NULL;
	}
	refcount = atomic_inc_return(&hw_blk->refcount);
	if (refcount == 1 && hw_blk->ops.start) {
		rc = hw_blk->ops.start(hw_blk);
		if (rc) {
			pr_err("failed to start  hw_blk:%d rc:%d\n", type, rc);
			goto error_start;
		}
	}
	pr_debug("hw_blk:%d.%d refcount:%d\n", hw_blk->type,
			hw_blk->id, refcount);
	return hw_blk;
error_start:
	dpu_hw_blk_put(hw_blk);
	return ERR_PTR(rc);
}
struct dpu_hw_blk * dpu_hw_blk_get ( struct dpu_hw_blk * hw_blk , u32 type , int id ) { struct dpu_hw_blk * curr ; int rc , refcount ; if ( ! hw_blk ) { mutex_lock ( & dpu_hw_blk_lock ) ; list_for_each_entry ( curr , & dpu_hw_blk_list , list ) { if ( ( curr -> type != type ) || ( id >= 0 && curr -> id != id ) || ( id < 0 && atomic_read ( & curr -> refcount ) ) ) continue ; hw_blk = curr ; break ; } mutex_unlock ( & dpu_hw_blk_lock ) ; } if ( ! hw_blk ) { pr_debug ( " \n " , type ) ; return NULL ; } refcount = atomic_inc_return ( & hw_blk -> refcount ) ; if ( refcount == 1 && hw_blk -> ops . start ) { rc = hw_blk -> ops . start ( hw_blk ) ; if ( rc ) { pr_err ( " \n " , type , rc ) ; goto error_start ; } } pr_debug ( " \n " , hw_blk -> type , hw_blk -> id , refcount ) ; return hw_blk ; error_start : dpu_hw_blk_put ( hw_blk ) ; return ERR_PTR ( rc ) ; }
dpu_hw_blk_get - get hw_blk from free pool
 @hw_blk: if specified, increment reference count only
 @type: if hw_blk is not specified, allocate the next available of this type
 @id: if specified (>= 0), allocate the given instance of the above type
 return: pointer to hw block object
dpu_hw_blk_get - get hw_blk from free pool @hw_blk : if specified increment reference count only @type : if hw_blk is not specified allocate the next available of this type @id : if specified ( > = 0 ) allocate the given instance of the above type return : pointer to hw block object