drivers/interconnect/icc-kunit.c

Source file repositories/reference/linux-study-clean/drivers/interconnect/icc-kunit.c

File Facts

System
Linux kernel
Corpus path
drivers/interconnect/icc-kunit.c
Extension
.c
Size
8260 bytes
Lines
325
Domain
Driver Families
Bucket
drivers/interconnect
Inferred role
Driver Families: implementation source
Status
source 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

struct test_node_data {
	int id;
	const char *name;
	int num_links;
	int links[2];
};

/*
 * Static Topology:
 * CPU -\
 * -> BUS -> DDR
 * GPU -/
 */
static const struct test_node_data test_topology[] = {
	{ NODE_CPU, "cpu", 1, { NODE_BUS } },
	{ NODE_GPU, "gpu", 1, { NODE_BUS } },
	{ NODE_BUS, "bus", 1, { NODE_DDR } },
	{ NODE_DDR, "ddr", 0, { } },
};

struct icc_test_priv {
	struct icc_provider provider;
	struct platform_device *pdev;
	struct icc_node *nodes[NODE_MAX];
};

static struct icc_node *get_node(struct icc_test_priv *priv, int id)
{
	int idx = id - NODE_CPU;

	if (idx < 0 || idx >= ARRAY_SIZE(test_topology))
		return NULL;
	return priv->nodes[idx];
}

static int icc_test_set(struct icc_node *src, struct icc_node *dst)
{
	return 0;
}

static int icc_test_aggregate(struct icc_node *node, u32 tag, u32 avg_bw,
			      u32 peak_bw, u32 *agg_avg, u32 *agg_peak)
{
	return icc_std_aggregate(node, tag, avg_bw, peak_bw, agg_avg, agg_peak);
}

static struct icc_node *icc_test_xlate(const struct of_phandle_args *spec, void *data)
{
	return NULL;
}

static int icc_test_get_bw(struct icc_node *node, u32 *avg, u32 *peak)
{
	*avg = 0;
	*peak = 0;

	return 0;
}

static int icc_test_init(struct kunit *test)
{
	struct icc_test_priv *priv;
	struct icc_node *node;
	int i, j, ret;

	priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv);
	test->priv = priv;

	priv->pdev = kunit_platform_device_alloc(test, "icc-test-dev", -1);
	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->pdev);
	KUNIT_ASSERT_EQ(test, kunit_platform_device_add(test, priv->pdev), 0);

	priv->provider.set = icc_test_set;
	priv->provider.aggregate = icc_test_aggregate;
	priv->provider.xlate = icc_test_xlate;
	priv->provider.get_bw = icc_test_get_bw;
	priv->provider.dev = &priv->pdev->dev;
	priv->provider.data = priv;
	INIT_LIST_HEAD(&priv->provider.nodes);

	ret = icc_provider_register(&priv->provider);
	KUNIT_ASSERT_EQ(test, ret, 0);

	for (i = 0; i < ARRAY_SIZE(test_topology); i++) {
		const struct test_node_data *data = &test_topology[i];

		node = icc_node_create(data->id);
		KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);

Annotation

Implementation Notes