drivers/most/core.c

Source file repositories/reference/linux-study-clean/drivers/most/core.c

File Facts

System
Linux kernel
Corpus path
drivers/most/core.c
Extension
.c
Size
36090 bytes
Lines
1498
Domain
Driver Families
Bucket
drivers/most
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 int most_match(struct device *dev, const struct device_driver *drv)
{
	if (!strcmp(dev_name(dev), "most"))
		return 0;
	else
		return 1;
}

static const struct bus_type mostbus = {
	.name = "most",
	.match = most_match,
};

static ssize_t links_show(struct device_driver *drv, char *buf)
{
	struct show_links_data d = { .buf = buf };

	bus_for_each_dev(&mostbus, NULL, &d, print_links);
	return d.offs;
}

static ssize_t components_show(struct device_driver *drv, char *buf)
{
	struct most_component *comp;
	int offs = 0;

	list_for_each_entry(comp, &comp_list, list) {
		offs += scnprintf(buf + offs, PAGE_SIZE - offs, "%s\n",
				 comp->name);
	}
	return offs;
}

/**
 * get_channel - get pointer to channel
 * @mdev: name of the device interface
 * @mdev_ch: name of channel
 */
static struct most_channel *get_channel(char *mdev, char *mdev_ch)
{
	struct device *dev = NULL;
	struct most_interface *iface;
	struct most_channel *c, *tmp;

	dev = bus_find_device_by_name(&mostbus, NULL, mdev);
	if (!dev)
		return NULL;
	iface = dev_get_drvdata(dev);
	put_device(dev);
	list_for_each_entry_safe(c, tmp, &iface->p->channel_list, list) {
		if (!strcmp(dev_name(&c->dev), mdev_ch))
			return c;
	}
	return NULL;
}

static
inline int link_channel_to_component(struct most_channel *c,
				     struct most_component *comp,
				     char *name,
				     char *comp_param)
{
	int ret;
	struct most_component **comp_ptr;

	if (!c->pipe0.comp)
		comp_ptr = &c->pipe0.comp;
	else if (!c->pipe1.comp)
		comp_ptr = &c->pipe1.comp;
	else
		return -ENOSPC;

	*comp_ptr = comp;
	ret = comp->probe_channel(c->iface, c->channel_id, &c->cfg, name,
				  comp_param);
	if (ret) {
		*comp_ptr = NULL;
		return ret;
	}
	return 0;
}

int most_set_cfg_buffer_size(char *mdev, char *mdev_ch, u16 val)
{
	struct most_channel *c = get_channel(mdev, mdev_ch);

	if (!c)
		return -ENODEV;
	c->cfg.buffer_size = val;
	return 0;

Annotation

Implementation Notes