drivers/cpuidle/dt_idle_genpd.c

Source file repositories/reference/linux-study-clean/drivers/cpuidle/dt_idle_genpd.c

File Facts

System
Linux kernel
Corpus path
drivers/cpuidle/dt_idle_genpd.c
Extension
.c
Size
4068 bytes
Lines
197
Domain
Driver Families
Bucket
drivers/cpuidle
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

if (!state_buf) {
			ret = -ENOMEM;
			goto free_state;
		}
		*state_buf = state;
		states[i].data = state_buf;
	}

	return 0;

free_state:
	i--;
	for (; i >= 0; i--)
		kfree(states[i].data);
	return ret;
}

static int pd_parse_states(struct device_node *np,
			   int (*parse_state)(struct device_node *, u32 *),
			   struct genpd_power_state **states,
			   int *state_count)
{
	int ret;

	/* Parse the domain idle states. */
	ret = of_genpd_parse_idle_states(np, states, state_count);
	if (ret)
		return ret;

	/* Fill out the dt specifics for each found state. */
	ret = pd_parse_state_nodes(parse_state, *states, *state_count);
	if (ret)
		kfree(*states);

	return ret;
}

static void pd_free_states(struct genpd_power_state *states,
			    unsigned int state_count)
{
	int i;

	for (i = 0; i < state_count; i++)
		kfree(states[i].data);
	kfree(states);
}

void dt_idle_pd_free(struct generic_pm_domain *pd)
{
	pd_free_states(pd->states, pd->state_count);
	kfree(pd->name);
	kfree(pd);
}

struct generic_pm_domain *dt_idle_pd_alloc(struct device_node *np,
			int (*parse_state)(struct device_node *, u32 *))
{
	struct generic_pm_domain *pd;
	struct genpd_power_state *states = NULL;
	int ret, state_count = 0;

	pd = kzalloc_obj(*pd);
	if (!pd)
		goto out;

	pd->name = kasprintf(GFP_KERNEL, "%pOF", np);
	if (!pd->name)
		goto free_pd;

	/*
	 * Parse the domain idle states and let genpd manage the state selection
	 * for those being compatible with "domain-idle-state".
	 */
	ret = pd_parse_states(np, parse_state, &states, &state_count);
	if (ret)
		goto free_name;

	pd->free_states = pd_free_states;
	pd->name = kbasename(pd->name);
	pd->states = states;
	pd->state_count = state_count;

	pr_debug("alloc PM domain %s\n", pd->name);
	return pd;

free_name:
	kfree(pd->name);
free_pd:
	kfree(pd);
out:

Annotation

Implementation Notes