drivers/cdx/cdx.c
Source file repositories/reference/linux-study-clean/drivers/cdx/cdx.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/cdx/cdx.c- Extension
.c- Size
- 25095 bytes
- Lines
- 942
- Domain
- Driver Families
- Bucket
- drivers/cdx
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/init.hlinux/irqdomain.hlinux/kernel.hlinux/of.hlinux/of_device.hlinux/of_platform.hlinux/platform_device.hlinux/slab.hlinux/mm.hlinux/idr.hlinux/cdx/cdx_bus.hlinux/iommu.hlinux/dma-map-ops.hlinux/debugfs.hcdx.h
Detected Declarations
function cdx_dev_resetfunction device_for_each_childfunction bus_for_each_devfunction cdx_unregister_devicesfunction cdx_match_one_devicefunction cdx_match_idfunction cdx_set_masterfunction cdx_clear_masterfunction cdx_bus_matchfunction cdx_probefunction cdx_removefunction cdx_shutdownfunction cdx_dma_configurefunction cdx_dma_cleanupfunction remove_storefunction reset_storefunction modalias_showfunction enable_storefunction enable_showfunction cdx_dev_attrs_are_visiblefunction cdx_bus_attrs_are_visiblefunction cdx_debug_resource_showfunction cdx_device_debugfs_initfunction rescan_storefunction __cdx_driver_registerfunction cdx_driver_unregisterfunction cdx_device_releasefunction cdx_mmap_resourcefunction cdx_destroy_res_attrfunction cdx_create_res_attrfunction cdx_device_addfunction cdx_register_controllerfunction cdx_unregister_controllerfunction cdx_bus_initexport cdx_dev_resetexport cdx_set_masterexport cdx_clear_masterexport cdx_bus_typeexport __cdx_driver_registerexport cdx_driver_unregister
Annotated Snippet
static void cdx_unregister_devices(const struct bus_type *bus)
{
/* Reset all the devices attached to cdx bus */
bus_for_each_dev(bus, NULL, NULL, cdx_unregister_device);
}
/**
* cdx_match_one_device - Tell if a CDX device structure has a matching
* CDX device id structure
* @id: single CDX device id structure to match
* @dev: the CDX device structure to match against
*
* Return: matching cdx_device_id structure or NULL if there is no match.
*/
static inline const struct cdx_device_id *
cdx_match_one_device(const struct cdx_device_id *id,
const struct cdx_device *dev)
{
/* Use vendor ID and device ID for matching */
if ((id->vendor == CDX_ANY_ID || id->vendor == dev->vendor) &&
(id->device == CDX_ANY_ID || id->device == dev->device) &&
(id->subvendor == CDX_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
(id->subdevice == CDX_ANY_ID || id->subdevice == dev->subsystem_device) &&
!((id->class ^ dev->class) & id->class_mask))
return id;
return NULL;
}
/**
* cdx_match_id - See if a CDX device matches a given cdx_id table
* @ids: array of CDX device ID structures to search in
* @dev: the CDX device structure to match against.
*
* Used by a driver to check whether a CDX device is in its list of
* supported devices. Returns the matching cdx_device_id structure or
* NULL if there is no match.
*
* Return: matching cdx_device_id structure or NULL if there is no match.
*/
static inline const struct cdx_device_id *
cdx_match_id(const struct cdx_device_id *ids, struct cdx_device *dev)
{
if (ids) {
while (ids->vendor || ids->device) {
if (cdx_match_one_device(ids, dev))
return ids;
ids++;
}
}
return NULL;
}
int cdx_set_master(struct cdx_device *cdx_dev)
{
struct cdx_controller *cdx = cdx_dev->cdx;
struct cdx_device_config dev_config;
int ret = -EOPNOTSUPP;
dev_config.type = CDX_DEV_BUS_MASTER_CONF;
dev_config.bus_master_enable = true;
if (cdx->ops->dev_configure)
ret = cdx->ops->dev_configure(cdx, cdx_dev->bus_num,
cdx_dev->dev_num, &dev_config);
return ret;
}
EXPORT_SYMBOL_GPL(cdx_set_master);
int cdx_clear_master(struct cdx_device *cdx_dev)
{
struct cdx_controller *cdx = cdx_dev->cdx;
struct cdx_device_config dev_config;
int ret = -EOPNOTSUPP;
dev_config.type = CDX_DEV_BUS_MASTER_CONF;
dev_config.bus_master_enable = false;
if (cdx->ops->dev_configure)
ret = cdx->ops->dev_configure(cdx, cdx_dev->bus_num,
cdx_dev->dev_num, &dev_config);
return ret;
}
EXPORT_SYMBOL_GPL(cdx_clear_master);
/**
* cdx_bus_match - device to driver matching callback
* @dev: the cdx device to match against
* @drv: the device driver to search for matching cdx device
* structures
*
Annotation
- Immediate include surface: `linux/init.h`, `linux/irqdomain.h`, `linux/kernel.h`, `linux/of.h`, `linux/of_device.h`, `linux/of_platform.h`, `linux/platform_device.h`, `linux/slab.h`.
- Detected declarations: `function cdx_dev_reset`, `function device_for_each_child`, `function bus_for_each_dev`, `function cdx_unregister_devices`, `function cdx_match_one_device`, `function cdx_match_id`, `function cdx_set_master`, `function cdx_clear_master`, `function cdx_bus_match`, `function cdx_probe`.
- Atlas domain: Driver Families / drivers/cdx.
- Implementation status: pattern 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.