drivers/pnp/driver.c
Source file repositories/reference/linux-study-clean/drivers/pnp/driver.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pnp/driver.c- Extension
.c- Size
- 7118 bytes
- Lines
- 342
- Domain
- Driver Families
- Bucket
- drivers/pnp
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/string.hlinux/list.hlinux/module.hlinux/ctype.hlinux/slab.hlinux/pnp.hbase.h
Detected Declarations
function compare_funcfunction compare_pnp_idfunction pnp_device_attachfunction pnp_device_detachfunction pnp_device_probefunction pnp_device_removefunction pnp_device_shutdownfunction pnp_ueventfunction pnp_bus_matchfunction __pnp_bus_suspendfunction pnp_bus_suspendfunction pnp_bus_freezefunction pnp_bus_powerofffunction pnp_bus_resumefunction dev_is_pnpfunction pnp_register_driverfunction pnp_unregister_driverexport pnp_device_attachexport pnp_device_detachexport dev_is_pnpexport pnp_register_driverexport pnp_unregister_driver
Annotated Snippet
static int pnp_bus_match(struct device *dev, const struct device_driver *drv)
{
struct pnp_dev *pnp_dev = to_pnp_dev(dev);
const struct pnp_driver *pnp_drv = to_pnp_driver(drv);
if (match_device(pnp_drv, pnp_dev) == NULL)
return 0;
return 1;
}
static int __pnp_bus_suspend(struct device *dev, pm_message_t state)
{
struct pnp_dev *pnp_dev = to_pnp_dev(dev);
struct pnp_driver *pnp_drv = pnp_dev->driver;
int error;
if (!pnp_drv)
return 0;
if (pnp_drv->driver.pm && pnp_drv->driver.pm->suspend) {
error = pnp_drv->driver.pm->suspend(dev);
suspend_report_result(dev, pnp_drv->driver.pm->suspend, error);
if (error)
return error;
}
if (pnp_drv->suspend) {
error = pnp_drv->suspend(pnp_dev, state);
if (error)
return error;
}
/* can_write is necessary to be able to re-start the device on resume */
if (pnp_can_disable(pnp_dev) && pnp_can_write(pnp_dev)) {
error = pnp_stop_dev(pnp_dev);
if (error)
return error;
}
if (pnp_can_suspend(pnp_dev))
pnp_dev->protocol->suspend(pnp_dev, state);
return 0;
}
static int pnp_bus_suspend(struct device *dev)
{
return __pnp_bus_suspend(dev, PMSG_SUSPEND);
}
static int pnp_bus_freeze(struct device *dev)
{
return __pnp_bus_suspend(dev, PMSG_FREEZE);
}
static int pnp_bus_poweroff(struct device *dev)
{
return __pnp_bus_suspend(dev, PMSG_HIBERNATE);
}
static int pnp_bus_resume(struct device *dev)
{
struct pnp_dev *pnp_dev = to_pnp_dev(dev);
struct pnp_driver *pnp_drv = pnp_dev->driver;
int error;
if (!pnp_drv)
return 0;
if (pnp_dev->protocol->resume) {
error = pnp_dev->protocol->resume(pnp_dev);
if (error)
return error;
}
if (pnp_can_write(pnp_dev)) {
error = pnp_start_dev(pnp_dev);
if (error)
return error;
}
if (pnp_drv->driver.pm && pnp_drv->driver.pm->resume) {
error = pnp_drv->driver.pm->resume(dev);
if (error)
return error;
}
if (pnp_drv->resume) {
error = pnp_drv->resume(pnp_dev);
if (error)
return error;
Annotation
- Immediate include surface: `linux/string.h`, `linux/list.h`, `linux/module.h`, `linux/ctype.h`, `linux/slab.h`, `linux/pnp.h`, `base.h`.
- Detected declarations: `function compare_func`, `function compare_pnp_id`, `function pnp_device_attach`, `function pnp_device_detach`, `function pnp_device_probe`, `function pnp_device_remove`, `function pnp_device_shutdown`, `function pnp_uevent`, `function pnp_bus_match`, `function __pnp_bus_suspend`.
- Atlas domain: Driver Families / drivers/pnp.
- Implementation status: pattern implementation candidate.
- 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.