drivers/of/address.c
Source file repositories/reference/linux-study-clean/drivers/of/address.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/of/address.c- Extension
.c- Size
- 30545 bytes
- Lines
- 1171
- Domain
- Driver Families
- Bucket
- drivers/of
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/fwnode.hlinux/io.hlinux/ioport.hlinux/logic_pio.hlinux/module.hlinux/of_address.hlinux/overflow.hlinux/pci.hlinux/pci_regs.hlinux/sizes.hlinux/slab.hlinux/string.hlinux/dma-direct.hkunit/visibility.hof_private.h
Detected Declarations
struct of_busfunction translatorfunction of_bus_default_mapfunction of_bus_default_translatefunction of_bus_default_flags_get_flagsfunction of_bus_default_get_flagsfunction of_bus_default_flags_mapfunction of_bus_default_flags_translatefunction of_bus_pci_get_flagsfunction of_node_is_pciefunction of_bus_pci_matchfunction of_bus_pci_count_cellsfunction of_bus_pci_mapfunction __of_address_resource_boundsfunction pci_address_to_piofunction of_range_to_resourcefunction of_bus_isa_matchfunction of_bus_isa_count_cellsfunction of_bus_isa_mapfunction of_bus_isa_get_flagsfunction of_bus_default_flags_matchfunction of_bus_default_matchfunction of_empty_ranges_quirkfunction of_translate_onefunction strcmpfunction impossiblefunction of_translate_addressfunction of_translate_dma_addressfunction of_property_read_regfunction parser_initfunction of_pci_range_parser_initfunction of_pci_dma_range_parser_initfunction of_translate_ioportfunction addrfunction of_dma_get_max_cpu_addressfunction for_each_available_child_of_nodefunction of_dma_is_coherentfunction of_mmio_is_nonpostedfunction __of_address_to_resourcefunction pci_address_to_piofunction of_pci_address_to_resourceexport of_pci_range_to_resourceexport of_range_to_resourceexport of_translate_addressexport of_translate_dma_addressexport of_translate_dma_regionexport __of_get_addressexport of_property_read_reg
Annotated Snippet
struct of_bus {
const char *name;
const char *addresses;
int (*match)(struct device_node *parent);
void (*count_cells)(struct device_node *child,
int *addrc, int *sizec);
u64 (*map)(__be32 *addr, const __be32 *range,
int na, int ns, int pna, int fna);
int (*translate)(__be32 *addr, u64 offset, int na);
int flag_cells;
unsigned int (*get_flags)(const __be32 *addr);
};
/*
* Default translator (generic bus)
*/
static void of_bus_default_count_cells(struct device_node *dev,
int *addrc, int *sizec)
{
if (addrc)
*addrc = of_n_addr_cells(dev);
if (sizec)
*sizec = of_n_size_cells(dev);
}
static u64 of_bus_default_map(__be32 *addr, const __be32 *range,
int na, int ns, int pna, int fna)
{
u64 cp, s, da;
cp = of_read_number(range + fna, na - fna);
s = of_read_number(range + na + pna, ns);
da = of_read_number(addr + fna, na - fna);
pr_debug("default map, cp=%llx, s=%llx, da=%llx\n", cp, s, da);
if (da < cp || da >= (cp + s))
return OF_BAD_ADDR;
return da - cp;
}
static int of_bus_default_translate(__be32 *addr, u64 offset, int na)
{
u64 a = of_read_number(addr, na);
memset(addr, 0, na * 4);
a += offset;
if (na > 1)
addr[na - 2] = cpu_to_be32(a >> 32);
addr[na - 1] = cpu_to_be32(a & 0xffffffffu);
return 0;
}
static unsigned int of_bus_default_flags_get_flags(const __be32 *addr)
{
return of_read_number(addr, 1);
}
static unsigned int of_bus_default_get_flags(const __be32 *addr)
{
return IORESOURCE_MEM;
}
static u64 of_bus_default_flags_map(__be32 *addr, const __be32 *range, int na,
int ns, int pna, int fna)
{
/* Check that flags match */
if (*addr != *range)
return OF_BAD_ADDR;
return of_bus_default_map(addr, range, na, ns, pna, fna);
}
static int of_bus_default_flags_translate(__be32 *addr, u64 offset, int na)
{
/* Keep "flags" part (high cell) in translated address */
return of_bus_default_translate(addr + 1, offset, na - 1);
}
#ifdef CONFIG_PCI
static unsigned int of_bus_pci_get_flags(const __be32 *addr)
{
unsigned int flags = 0;
u32 w = be32_to_cpup(addr);
if (!IS_ENABLED(CONFIG_PCI))
return 0;
switch((w >> 24) & 0x03) {
Annotation
- Immediate include surface: `linux/device.h`, `linux/fwnode.h`, `linux/io.h`, `linux/ioport.h`, `linux/logic_pio.h`, `linux/module.h`, `linux/of_address.h`, `linux/overflow.h`.
- Detected declarations: `struct of_bus`, `function translator`, `function of_bus_default_map`, `function of_bus_default_translate`, `function of_bus_default_flags_get_flags`, `function of_bus_default_get_flags`, `function of_bus_default_flags_map`, `function of_bus_default_flags_translate`, `function of_bus_pci_get_flags`, `function of_node_is_pcie`.
- Atlas domain: Driver Families / drivers/of.
- Implementation status: integration 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.