drivers/ntb/core.c
Source file repositories/reference/linux-study-clean/drivers/ntb/core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/ntb/core.c- Extension
.c- Size
- 7907 bytes
- Lines
- 318
- Domain
- Driver Families
- Bucket
- drivers/ntb
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/kernel.hlinux/module.hlinux/ntb.hlinux/pci.h
Detected Declarations
function __ntb_register_clientfunction ntb_unregister_clientfunction ntb_register_devicefunction ntb_unregister_devicefunction ntb_set_ctxfunction ntb_clear_ctxfunction ntb_link_eventfunction ntb_db_eventfunction ntb_msg_eventfunction ntb_default_port_numberfunction ntb_default_peer_port_countfunction ntb_default_peer_port_numberfunction ntb_default_peer_port_idxfunction ntb_probefunction ntb_removefunction ntb_dev_releasefunction ntb_driver_initfunction ntb_driver_exitmodule init ntb_driver_initexport __ntb_register_clientexport ntb_unregister_clientexport ntb_register_deviceexport ntb_unregister_deviceexport ntb_set_ctxexport ntb_clear_ctxexport ntb_link_eventexport ntb_db_eventexport ntb_msg_eventexport ntb_default_port_numberexport ntb_default_peer_port_countexport ntb_default_peer_port_numberexport ntb_default_peer_port_idx
Annotated Snippet
static const struct bus_type ntb_bus;
static void ntb_dev_release(struct device *dev);
int __ntb_register_client(struct ntb_client *client, struct module *mod,
const char *mod_name)
{
if (!client)
return -EINVAL;
if (!ntb_client_ops_is_valid(&client->ops))
return -EINVAL;
memset(&client->drv, 0, sizeof(client->drv));
client->drv.bus = &ntb_bus;
client->drv.name = mod_name;
client->drv.owner = mod;
return driver_register(&client->drv);
}
EXPORT_SYMBOL(__ntb_register_client);
void ntb_unregister_client(struct ntb_client *client)
{
driver_unregister(&client->drv);
}
EXPORT_SYMBOL(ntb_unregister_client);
int ntb_register_device(struct ntb_dev *ntb)
{
int ret;
if (!ntb)
return -EINVAL;
if (!ntb->pdev)
return -EINVAL;
if (!ntb->ops)
return -EINVAL;
if (!ntb_dev_ops_is_valid(ntb->ops))
return -EINVAL;
init_completion(&ntb->released);
ntb->dev.bus = &ntb_bus;
ntb->dev.parent = &ntb->pdev->dev;
ntb->dev.release = ntb_dev_release;
dev_set_name(&ntb->dev, "%s", pci_name(ntb->pdev));
ntb->ctx = NULL;
ntb->ctx_ops = NULL;
spin_lock_init(&ntb->ctx_lock);
ret = device_register(&ntb->dev);
if (ret)
put_device(&ntb->dev);
return ret;
}
EXPORT_SYMBOL(ntb_register_device);
void ntb_unregister_device(struct ntb_dev *ntb)
{
device_unregister(&ntb->dev);
wait_for_completion(&ntb->released);
}
EXPORT_SYMBOL(ntb_unregister_device);
int ntb_set_ctx(struct ntb_dev *ntb, void *ctx,
const struct ntb_ctx_ops *ctx_ops)
{
unsigned long irqflags;
if (!ntb_ctx_ops_is_valid(ctx_ops))
return -EINVAL;
if (ntb->ctx_ops)
return -EINVAL;
spin_lock_irqsave(&ntb->ctx_lock, irqflags);
{
ntb->ctx = ctx;
ntb->ctx_ops = ctx_ops;
}
spin_unlock_irqrestore(&ntb->ctx_lock, irqflags);
return 0;
}
EXPORT_SYMBOL(ntb_set_ctx);
void ntb_clear_ctx(struct ntb_dev *ntb)
{
unsigned long irqflags;
Annotation
- Immediate include surface: `linux/device.h`, `linux/kernel.h`, `linux/module.h`, `linux/ntb.h`, `linux/pci.h`.
- Detected declarations: `function __ntb_register_client`, `function ntb_unregister_client`, `function ntb_register_device`, `function ntb_unregister_device`, `function ntb_set_ctx`, `function ntb_clear_ctx`, `function ntb_link_event`, `function ntb_db_event`, `function ntb_msg_event`, `function ntb_default_port_number`.
- Atlas domain: Driver Families / drivers/ntb.
- 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.