Source
x
static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device
// SPDX-License-Identifier: GPL-2.0
/*
* fsl-mc object allocator driver
*
* Copyright (C) 2013-2016 Freescale Semiconductor, Inc.
*
*/
static bool __must_check fsl_mc_is_allocatable(struct fsl_mc_device *mc_dev)
{
return is_fsl_mc_bus_dpbp(mc_dev) ||
is_fsl_mc_bus_dpmcp(mc_dev) ||
is_fsl_mc_bus_dpcon(mc_dev);
}
/**
* fsl_mc_resource_pool_add_device - add allocatable object to a resource
* pool of a given fsl-mc bus
*
* @mc_bus: pointer to the fsl-mc bus
* @pool_type: pool type
* @mc_dev: pointer to allocatable fsl-mc device
*/
static int __must_check fsl_mc_resource_pool_add_device(struct fsl_mc_bus
*mc_bus,
enum fsl_mc_pool_type
pool_type,
struct fsl_mc_device
*mc_dev)
{
struct fsl_mc_resource_pool *res_pool;
struct fsl_mc_resource *resource;
struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev;
int error = -EINVAL;
if (pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES)
goto out;
if (!fsl_mc_is_allocatable(mc_dev))
goto out;
if (mc_dev->resource)
goto out;
res_pool = &mc_bus->resource_pools[pool_type];
if (res_pool->type != pool_type)
goto out;
if (res_pool->mc_bus != mc_bus)
goto out;
mutex_lock(&res_pool->mutex);
if (res_pool->max_count < 0)
goto out_unlock;
if (res_pool->free_count < 0 ||
res_pool->free_count > res_pool->max_count)
goto out_unlock;
resource = devm_kzalloc(&mc_bus_dev->dev, sizeof(*resource),
GFP_KERNEL);
if (!resource) {
error = -ENOMEM;
dev_err(&mc_bus_dev->dev,
"Failed to allocate memory for fsl_mc_resource\n");
goto out_unlock;
}
resource->type = pool_type;
resource->id = mc_dev->obj_desc.id;
resource->data = mc_dev;
resource->parent_pool = res_pool;
INIT_LIST_HEAD(&resource->node);
list_add_tail(&resource->node, &res_pool->free_list);
mc_dev->resource = resource;
res_pool->free_count++;
res_pool->max_count++;
error = 0;
out_unlock:
mutex_unlock(&res_pool->mutex);
out:
return error;
}
/**
* fsl_mc_resource_pool_remove_device - remove an allocatable device from a
* resource pool
*
* @mc_dev: pointer to allocatable fsl-mc device