scripts/dtc/checks.c
Source file repositories/reference/linux-study-clean/scripts/dtc/checks.c
File Facts
- System
- Linux kernel
- Corpus path
scripts/dtc/checks.c- Extension
.c- Size
- 55848 bytes
- Lines
- 2083
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
dtc.hsrcpos.h
Detected Declarations
struct checkstruct checkstruct providerenum checkstatusfunction PRINTFfunction check_nodes_propsfunction is_multiple_offunction run_checkfunction check_always_failfunction check_is_stringfunction check_is_string_listfunction check_is_cellfunction check_duplicate_node_namesfunction check_duplicate_property_namesfunction for_each_propertyfunction check_node_name_charsfunction check_node_name_chars_strictfunction check_node_name_formatfunction check_node_name_not_emptyfunction check_node_name_vs_property_namefunction check_unit_address_vs_regfunction check_property_name_charsfunction for_each_propertyfunction check_property_name_chars_strictfunction for_each_propertyfunction check_duplicate_labelfunction check_duplicate_label_nodefunction for_each_propertyfunction check_phandle_propfunction check_explicit_phandlesfunction check_name_propertiesfunction fixup_phandle_referencesfunction for_each_propertyfunction for_each_marker_of_typefunction fixup_path_referencesfunction for_each_propertyfunction for_each_marker_of_typefunction fixup_omit_unused_nodesfunction check_names_is_string_listfunction for_each_propertyfunction check_alias_pathsfunction for_each_propertyfunction fixup_addr_size_cellsfunction check_reg_formatfunction check_ranges_formatfunction check_pci_bridgefunction check_pci_device_bus_numfunction check_pci_device_reg
Annotated Snippet
static const struct bus_type pci_bus = {
.name = "PCI",
};
static void check_pci_bridge(struct check *c, struct dt_info *dti, struct node *node)
{
struct property *prop;
cell_t *cells;
prop = get_property(node, "device_type");
if (!prop || !streq(prop->val.val, "pci"))
return;
node->bus = &pci_bus;
if (!strprefixeq(node->name, node->basenamelen, "pci") &&
!strprefixeq(node->name, node->basenamelen, "pcie"))
FAIL(c, dti, node, "node name is not \"pci\" or \"pcie\"");
prop = get_property(node, "ranges");
if (!prop)
FAIL(c, dti, node, "missing ranges for PCI bridge (or not a bridge)");
if (node_addr_cells(node) != 3)
FAIL(c, dti, node, "incorrect #address-cells for PCI bridge");
if (node_size_cells(node) != 2)
FAIL(c, dti, node, "incorrect #size-cells for PCI bridge");
prop = get_property(node, "bus-range");
if (!prop)
return;
if (prop->val.len != (sizeof(cell_t) * 2)) {
FAIL_PROP(c, dti, node, prop, "value must be 2 cells");
return;
}
cells = (cell_t *)prop->val.val;
if (fdt32_to_cpu(cells[0]) > fdt32_to_cpu(cells[1]))
FAIL_PROP(c, dti, node, prop, "1st cell must be less than or equal to 2nd cell");
if (fdt32_to_cpu(cells[1]) > 0xff)
FAIL_PROP(c, dti, node, prop, "maximum bus number must be less than 256");
}
WARNING(pci_bridge, check_pci_bridge, NULL,
&device_type_is_string, &addr_size_cells);
static void check_pci_device_bus_num(struct check *c, struct dt_info *dti, struct node *node)
{
struct property *prop;
unsigned int bus_num, min_bus, max_bus;
cell_t *cells;
if (!node->parent || (node->parent->bus != &pci_bus))
return;
prop = get_property(node, "reg");
if (!prop)
return;
cells = (cell_t *)prop->val.val;
bus_num = (fdt32_to_cpu(cells[0]) & 0x00ff0000) >> 16;
prop = get_property(node->parent, "bus-range");
if (!prop) {
min_bus = max_bus = 0;
} else {
cells = (cell_t *)prop->val.val;
min_bus = fdt32_to_cpu(cells[0]);
max_bus = fdt32_to_cpu(cells[1]);
}
if ((bus_num < min_bus) || (bus_num > max_bus))
FAIL_PROP(c, dti, node, prop, "PCI bus number %d out of range, expected (%d - %d)",
bus_num, min_bus, max_bus);
}
WARNING(pci_device_bus_num, check_pci_device_bus_num, NULL, ®_format, &pci_bridge);
static void check_pci_device_reg(struct check *c, struct dt_info *dti, struct node *node)
{
struct property *prop;
const char *unitname = get_unitname(node);
char unit_addr[5];
unsigned int dev, func, reg;
cell_t *cells;
if (!node->parent || (node->parent->bus != &pci_bus))
return;
prop = get_property(node, "reg");
if (!prop)
return;
Annotation
- Immediate include surface: `dtc.h`, `srcpos.h`.
- Detected declarations: `struct check`, `struct check`, `struct provider`, `enum checkstatus`, `function PRINTF`, `function check_nodes_props`, `function is_multiple_of`, `function run_check`, `function check_always_fail`, `function check_is_string`.
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: pattern implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.