drivers/char/ps3flash.c
Source file repositories/reference/linux-study-clean/drivers/char/ps3flash.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/ps3flash.c- Extension
.c- Size
- 10245 bytes
- Lines
- 446
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/fs.hlinux/miscdevice.hlinux/slab.hlinux/uaccess.hlinux/module.hasm/lv1call.hasm/ps3stor.h
Detected Declarations
struct ps3flash_privatefunction ps3flash_read_write_sectorsfunction ps3flash_writebackfunction ps3flash_fetchfunction ps3flash_llseekfunction ps3flash_readfunction ps3flash_writefunction ps3flash_user_readfunction ps3flash_user_writefunction ps3flash_kernel_readfunction ps3flash_kernel_writefunction ps3flash_flushfunction ps3flash_fsyncfunction ps3flash_interruptfunction ps3flash_probefunction ps3flash_removefunction ps3flash_initfunction ps3flash_exitmodule init ps3flash_init
Annotated Snippet
static const struct file_operations ps3flash_fops = {
.owner = THIS_MODULE,
.llseek = ps3flash_llseek,
.read = ps3flash_user_read,
.write = ps3flash_user_write,
.flush = ps3flash_flush,
.fsync = ps3flash_fsync,
};
static const struct ps3_os_area_flash_ops ps3flash_kernel_ops = {
.read = ps3flash_kernel_read,
.write = ps3flash_kernel_write,
};
static struct miscdevice ps3flash_misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &ps3flash_fops,
};
static int ps3flash_probe(struct ps3_system_bus_device *_dev)
{
struct ps3_storage_device *dev = to_ps3_storage_device(&_dev->core);
struct ps3flash_private *priv;
int error;
unsigned long tmp;
tmp = dev->regions[dev->region_idx].start*dev->blk_size;
if (tmp % FLASH_BLOCK_SIZE) {
dev_err(&dev->sbd.core,
"%s:%u region start %lu is not aligned\n", __func__,
__LINE__, tmp);
return -EINVAL;
}
tmp = dev->regions[dev->region_idx].size*dev->blk_size;
if (tmp % FLASH_BLOCK_SIZE) {
dev_err(&dev->sbd.core,
"%s:%u region size %lu is not aligned\n", __func__,
__LINE__, tmp);
return -EINVAL;
}
/* use static buffer, kmalloc cannot allocate 256 KiB */
if (!ps3flash_bounce_buffer.address)
return -ENODEV;
if (ps3flash_dev) {
dev_err(&dev->sbd.core,
"Only one FLASH device is supported\n");
return -EBUSY;
}
ps3flash_dev = dev;
priv = kzalloc_obj(*priv);
if (!priv) {
error = -ENOMEM;
goto fail;
}
ps3_system_bus_set_drvdata(&dev->sbd, priv);
mutex_init(&priv->mutex);
priv->tag = -1;
dev->bounce_size = ps3flash_bounce_buffer.size;
dev->bounce_buf = ps3flash_bounce_buffer.address;
priv->chunk_sectors = dev->bounce_size / dev->blk_size;
error = ps3stor_setup(dev, ps3flash_interrupt);
if (error)
goto fail_free_priv;
ps3flash_misc.parent = &dev->sbd.core;
error = misc_register(&ps3flash_misc);
if (error) {
dev_err(&dev->sbd.core, "%s:%u: misc_register failed %d\n",
__func__, __LINE__, error);
goto fail_teardown;
}
dev_info(&dev->sbd.core, "%s:%u: registered misc device %d\n",
__func__, __LINE__, ps3flash_misc.minor);
ps3_os_area_flash_register(&ps3flash_kernel_ops);
return 0;
fail_teardown:
ps3stor_teardown(dev);
fail_free_priv:
kfree(priv);
Annotation
- Immediate include surface: `linux/fs.h`, `linux/miscdevice.h`, `linux/slab.h`, `linux/uaccess.h`, `linux/module.h`, `asm/lv1call.h`, `asm/ps3stor.h`.
- Detected declarations: `struct ps3flash_private`, `function ps3flash_read_write_sectors`, `function ps3flash_writeback`, `function ps3flash_fetch`, `function ps3flash_llseek`, `function ps3flash_read`, `function ps3flash_write`, `function ps3flash_user_read`, `function ps3flash_user_write`, `function ps3flash_kernel_read`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.