drivers/char/nwflash.c
Source file repositories/reference/linux-study-clean/drivers/char/nwflash.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/nwflash.c- Extension
.c- Size
- 13145 bytes
- Lines
- 628
- Domain
- Driver Families
- Bucket
- drivers/char
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/types.hlinux/fs.hlinux/errno.hlinux/mm.hlinux/delay.hlinux/proc_fs.hlinux/miscdevice.hlinux/spinlock.hlinux/rwsem.hlinux/init.hlinux/mutex.hlinux/jiffies.hasm/hardware/dec21285.hasm/io.hasm/mach-types.hlinux/uaccess.hasm/nwflash.h
Detected Declarations
function get_flash_idfunction flash_ioctlfunction flash_readfunction flash_writefunction flash_llseekfunction erase_blockfunction write_blockfunction kick_openfunction nwflash_initfunction nwflash_exitmodule init nwflash_init
Annotated Snippet
static const struct file_operations flash_fops =
{
.owner = THIS_MODULE,
.llseek = flash_llseek,
.read = flash_read,
.write = flash_write,
.unlocked_ioctl = flash_ioctl,
};
static struct miscdevice flash_miscdev =
{
NWFLASH_MINOR,
"nwflash",
&flash_fops
};
static int __init nwflash_init(void)
{
int ret = -ENODEV;
if (machine_is_netwinder()) {
int id;
FLASH_BASE = ioremap(DC21285_FLASH, KFLASH_SIZE4);
if (!FLASH_BASE)
goto out;
id = get_flash_id();
if ((id != KFLASH_ID) && (id != KFLASH_ID4)) {
ret = -ENXIO;
iounmap((void *)FLASH_BASE);
printk("Flash: incorrect ID 0x%04X.\n", id);
goto out;
}
printk("Flash ROM driver v.%s, flash device ID 0x%04X, size %d Mb.\n",
NWFLASH_VERSION, id, gbFlashSize / (1024 * 1024));
ret = misc_register(&flash_miscdev);
if (ret < 0) {
iounmap((void *)FLASH_BASE);
}
}
out:
return ret;
}
static void __exit nwflash_exit(void)
{
misc_deregister(&flash_miscdev);
iounmap((void *)FLASH_BASE);
}
MODULE_DESCRIPTION("NetWinder flash memory driver");
MODULE_LICENSE("GPL");
module_param(flashdebug, bool, 0644);
module_init(nwflash_init);
module_exit(nwflash_exit);
Annotation
- Immediate include surface: `linux/module.h`, `linux/types.h`, `linux/fs.h`, `linux/errno.h`, `linux/mm.h`, `linux/delay.h`, `linux/proc_fs.h`, `linux/miscdevice.h`.
- Detected declarations: `function get_flash_id`, `function flash_ioctl`, `function flash_read`, `function flash_write`, `function flash_llseek`, `function erase_block`, `function write_block`, `function kick_open`, `function nwflash_init`, `function nwflash_exit`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.