drivers/firmware/broadcom/bcm47xx_nvram.c
Source file repositories/reference/linux-study-clean/drivers/firmware/broadcom/bcm47xx_nvram.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/firmware/broadcom/bcm47xx_nvram.c- Extension
.c- Size
- 6207 bytes
- Lines
- 258
- Domain
- Driver Families
- Bucket
- drivers/firmware
- 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/io.hlinux/types.hlinux/module.hlinux/kernel.hlinux/string.hlinux/mtd/mtd.hlinux/bcm47xx_nvram.h
Detected Declarations
struct nvram_headerfunction bcm47xx_nvram_is_validfunction bcm47xx_nvram_copyfunction bcm47xx_nvram_find_and_copyfunction bcm47xx_nvram_init_from_iomemfunction bcm47xx_nvram_init_from_memfunction nvram_initfunction bcm47xx_nvram_getenvfunction bcm47xx_nvram_gpio_pinexport bcm47xx_nvram_init_from_iomemexport bcm47xx_nvram_getenvexport bcm47xx_nvram_gpio_pinexport bcm47xx_nvram_get_contents
Annotated Snippet
struct nvram_header {
u32 magic;
u32 len;
u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
u32 config_ncdl; /* ncdl values for memc */
};
static char nvram_buf[NVRAM_SPACE];
static size_t nvram_len;
static const u32 nvram_sizes[] = {0x6000, 0x8000, 0xF000, 0x10000};
/**
* bcm47xx_nvram_is_valid - check for a valid NVRAM at specified memory
*/
static bool bcm47xx_nvram_is_valid(void __iomem *nvram)
{
return ((struct nvram_header *)nvram)->magic == NVRAM_MAGIC;
}
/**
* bcm47xx_nvram_copy - copy NVRAM to internal buffer
*/
static void bcm47xx_nvram_copy(void __iomem *nvram_start, size_t res_size)
{
struct nvram_header __iomem *header = nvram_start;
size_t copy_size;
copy_size = header->len;
if (copy_size > res_size) {
pr_err("The nvram size according to the header seems to be bigger than the partition on flash\n");
copy_size = res_size;
}
if (copy_size >= NVRAM_SPACE) {
pr_err("nvram on flash (%zu bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
copy_size, NVRAM_SPACE - 1);
copy_size = NVRAM_SPACE - 1;
}
__ioread32_copy(nvram_buf, nvram_start, DIV_ROUND_UP(copy_size, 4));
nvram_buf[NVRAM_SPACE - 1] = '\0';
nvram_len = copy_size;
}
/**
* bcm47xx_nvram_find_and_copy - find NVRAM on flash mapping & copy it
*/
static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_size)
{
size_t flash_size;
size_t offset;
int i;
if (nvram_len) {
pr_warn("nvram already initialized\n");
return -EEXIST;
}
/* TODO: when nvram is on nand flash check for bad blocks first. */
/* Try every possible flash size and check for NVRAM at its end */
for (flash_size = FLASH_MIN; flash_size <= res_size; flash_size <<= 1) {
for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
offset = flash_size - nvram_sizes[i];
if (bcm47xx_nvram_is_valid(flash_start + offset))
goto found;
}
}
/* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
offset = 4096;
if (bcm47xx_nvram_is_valid(flash_start + offset))
goto found;
offset = 1024;
if (bcm47xx_nvram_is_valid(flash_start + offset))
goto found;
pr_err("no nvram found\n");
return -ENXIO;
found:
bcm47xx_nvram_copy(flash_start + offset, res_size - offset);
return 0;
}
int bcm47xx_nvram_init_from_iomem(void __iomem *nvram_start, size_t res_size)
{
Annotation
- Immediate include surface: `linux/io.h`, `linux/types.h`, `linux/module.h`, `linux/kernel.h`, `linux/string.h`, `linux/mtd/mtd.h`, `linux/bcm47xx_nvram.h`.
- Detected declarations: `struct nvram_header`, `function bcm47xx_nvram_is_valid`, `function bcm47xx_nvram_copy`, `function bcm47xx_nvram_find_and_copy`, `function bcm47xx_nvram_init_from_iomem`, `function bcm47xx_nvram_init_from_mem`, `function nvram_init`, `function bcm47xx_nvram_getenv`, `function bcm47xx_nvram_gpio_pin`, `export bcm47xx_nvram_init_from_iomem`.
- Atlas domain: Driver Families / drivers/firmware.
- 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.