arch/riscv/kernel/pi/fdt_early.c

Source file repositories/reference/linux-study-clean/arch/riscv/kernel/pi/fdt_early.c

File Facts

System
Linux kernel
Corpus path
arch/riscv/kernel/pi/fdt_early.c
Extension
.c
Size
5055 bytes
Lines
226
Domain
Architecture Layer
Bucket
arch/riscv
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

if (strncasecmp(isa_str, ext_name, len) == 0) {
			ext_end = isa_str[len];
			/* Check if matches the whole extension. */
			if (ext_end == '\0' || ext_end == '_')
				return true;
		}
		/* Multi-letter extensions must be split from other multi-letter
		 * extensions with an "_", the end of a multi-letter extension will
		 * either be the null character or the "_" at the start of the next
		 * multi-letter extension.
		 */
		isa_str = strchr(isa_str, '_');
		if (isa_str)
			isa_str++;
	}

	return false;
}

/**
 *  early_cpu_isa_ext_available - check if cpu node has an extension
 *
 * @fdt: pointer to the device tree blob
 * @node: offset of the cpu node
 * @ext_name: the extension to search for
 *
 *  Returns true if the cpu node has the extension,
 *  false otherwise
 */
static bool early_cpu_isa_ext_available(const void *fdt, int node, const char *ext_name)
{
	const void *prop;
	int len;

	prop = fdt_getprop(fdt, node, "riscv,isa-extensions", &len);
	if (prop && fdt_stringlist_contains(prop, len, ext_name))
		return true;

	prop = fdt_getprop(fdt, node, "riscv,isa", &len);
	if (prop && isa_string_contains(prop, ext_name))
		return true;

	return false;
}

/**
 *  fdt_early_match_extension_isa - check if all cpu nodes have an extension
 *
 * @fdt: pointer to the device tree blob
 * @ext_name: the extension to search for
 *
 *  Returns true if the all available the cpu nodes have the extension,
 *  false otherwise
 */
bool fdt_early_match_extension_isa(const void *fdt, const char *ext_name)
{
	int node, parent;
	bool ret = false;

	parent = fdt_path_offset(fdt, "/cpus");
	if (parent < 0)
		return false;

	fdt_for_each_subnode(node, fdt, parent) {
		if (!fdt_node_name_eq(fdt, node, "cpu"))
			continue;

		if (!fdt_device_is_available(fdt, node))
			continue;

		if (!early_cpu_isa_ext_available(fdt, node, ext_name))
			return false;

		ret = true;
	}

	return ret;
}

/**
 *  set_satp_mode_from_fdt - determine SATP mode based on the MMU type in fdt
 *
 * @dtb_pa: physical address of the device tree blob
 *
 *  Returns the SATP mode corresponding to the MMU type of the first enabled CPU,
 *  0 otherwise
 */
u64 set_satp_mode_from_fdt(uintptr_t dtb_pa)
{
	const void *fdt = (const void *)dtb_pa;

Annotation

Implementation Notes