drivers/bus/fsl-mc/fsl-mc-allocator.c
Source file repositories/reference/linux-study-clean/drivers/bus/fsl-mc/fsl-mc-allocator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/bus/fsl-mc/fsl-mc-allocator.c- Extension
.c- Size
- 15580 bytes
- Lines
- 638
- Domain
- Driver Families
- Bucket
- drivers/bus
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/msi.hlinux/fsl/mc.hfsl-mc-private.h
Detected Declarations
function Copyrightfunction fsl_mc_resource_pool_add_devicefunction fsl_mc_resource_pool_remove_devicefunction object_type_to_pool_typefunction fsl_mc_resource_allocatefunction fsl_mc_resource_freefunction fsl_mc_portal_allocatefunction fsl_mc_object_freefunction fsl_mc_populate_irq_poolfunction fsl_mc_cleanup_irq_poolfunction fsl_mc_allocate_irqsfunction fsl_mc_free_irqsfunction fsl_mc_init_all_resource_poolsfunction fsl_mc_allocator_probefunction fsl_mc_allocator_removefunction fsl_mc_allocator_driver_initexport fsl_mc_resource_allocateexport fsl_mc_resource_freeexport fsl_mc_object_allocateexport fsl_mc_object_freeexport fsl_mc_populate_irq_poolexport fsl_mc_cleanup_irq_poolexport fsl_mc_allocate_irqsexport fsl_mc_free_irqs
Annotated Snippet
if (strcmp(object_type, fsl_mc_pool_type_strings[i]) == 0) {
*pool_type = i;
return 0;
}
}
return -EINVAL;
}
int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
enum fsl_mc_pool_type pool_type,
struct fsl_mc_resource **new_resource)
{
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;
BUILD_BUG_ON(ARRAY_SIZE(fsl_mc_pool_type_strings) !=
FSL_MC_NUM_POOL_TYPES);
*new_resource = NULL;
if (pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES)
goto out;
res_pool = &mc_bus->resource_pools[pool_type];
if (res_pool->mc_bus != mc_bus)
goto out;
mutex_lock(&res_pool->mutex);
resource = list_first_entry_or_null(&res_pool->free_list,
struct fsl_mc_resource, node);
if (!resource) {
error = -ENXIO;
dev_err(&mc_bus_dev->dev,
"No more resources of type %s left\n",
fsl_mc_pool_type_strings[pool_type]);
goto out_unlock;
}
if (resource->type != pool_type)
goto out_unlock;
if (resource->parent_pool != res_pool)
goto out_unlock;
if (res_pool->free_count <= 0 ||
res_pool->free_count > res_pool->max_count)
goto out_unlock;
list_del_init(&resource->node);
res_pool->free_count--;
error = 0;
out_unlock:
mutex_unlock(&res_pool->mutex);
*new_resource = resource;
out:
return error;
}
EXPORT_SYMBOL_GPL(fsl_mc_resource_allocate);
void fsl_mc_resource_free(struct fsl_mc_resource *resource)
{
struct fsl_mc_resource_pool *res_pool;
res_pool = resource->parent_pool;
if (resource->type != res_pool->type)
return;
mutex_lock(&res_pool->mutex);
if (res_pool->free_count < 0 ||
res_pool->free_count >= res_pool->max_count)
goto out_unlock;
if (!list_empty(&resource->node))
goto out_unlock;
list_add_tail(&resource->node, &res_pool->free_list);
res_pool->free_count++;
out_unlock:
mutex_unlock(&res_pool->mutex);
}
EXPORT_SYMBOL_GPL(fsl_mc_resource_free);
/**
* fsl_mc_object_allocate - Allocates an fsl-mc object of the given
* pool type from a given fsl-mc bus instance
*
* @mc_dev: fsl-mc device which is used in conjunction with the
* allocated object
Annotation
- Immediate include surface: `linux/module.h`, `linux/msi.h`, `linux/fsl/mc.h`, `fsl-mc-private.h`.
- Detected declarations: `function Copyright`, `function fsl_mc_resource_pool_add_device`, `function fsl_mc_resource_pool_remove_device`, `function object_type_to_pool_type`, `function fsl_mc_resource_allocate`, `function fsl_mc_resource_free`, `function fsl_mc_portal_allocate`, `function fsl_mc_object_free`, `function fsl_mc_populate_irq_pool`, `function fsl_mc_cleanup_irq_pool`.
- Atlas domain: Driver Families / drivers/bus.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.