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.

Dependency Surface

Detected Declarations

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

Implementation Notes