drivers/ntb/hw/amd/ntb_hw_amd.c
Source file repositories/reference/linux-study-clean/drivers/ntb/hw/amd/ntb_hw_amd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/ntb/hw/amd/ntb_hw_amd.c- Extension
.c- Size
- 34015 bytes
- Lines
- 1373
- 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.
- 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/debugfs.hlinux/delay.hlinux/init.hlinux/interrupt.hlinux/module.hlinux/acpi.hlinux/pci.hlinux/random.hlinux/slab.hlinux/ntb.hntb_hw_amd.h
Detected Declarations
function ndev_mw_to_barfunction amd_ntb_mw_countfunction amd_ntb_mw_get_alignfunction amd_ntb_mw_set_transfunction amd_ntb_get_link_statusfunction amd_link_is_upfunction amd_ntb_link_is_upfunction amd_ntb_link_enablefunction amd_ntb_link_disablefunction amd_ntb_peer_mw_countfunction amd_ntb_peer_mw_get_addrfunction amd_ntb_db_valid_maskfunction amd_ntb_db_vector_countfunction amd_ntb_db_vector_maskfunction amd_ntb_db_readfunction amd_ntb_db_clearfunction amd_ntb_db_set_maskfunction amd_ntb_db_clear_maskfunction amd_ntb_peer_db_setfunction amd_ntb_spad_countfunction amd_ntb_spad_readfunction amd_ntb_spad_writefunction amd_ntb_peer_spad_readfunction amd_ntb_peer_spad_writefunction amd_ack_smufunction amd_handle_eventfunction amd_handle_db_eventfunction ndev_interruptfunction ndev_vec_isrfunction ndev_irq_isrfunction ndev_init_isrfunction ndev_deinit_isrfunction ndev_debugfs_readfunction ndev_init_debugfsfunction ndev_deinit_debugfsfunction ndev_init_structfunction amd_poll_linkfunction amd_link_hbfunction amd_init_isrfunction amd_set_side_info_regfunction amd_clear_side_info_regfunction amd_init_side_infofunction amd_deinit_side_infofunction amd_init_ntbfunction amd_get_topofunction amd_init_devfunction amd_deinit_devfunction amd_ntb_init_pci
Annotated Snippet
static const struct file_operations amd_ntb_debugfs_info;
static struct dentry *debugfs_dir;
static int ndev_mw_to_bar(struct amd_ntb_dev *ndev, int idx)
{
if (idx < 0 || idx > ndev->mw_count)
return -EINVAL;
return ndev->dev_data->mw_idx << idx;
}
static int amd_ntb_mw_count(struct ntb_dev *ntb, int pidx)
{
if (pidx != NTB_DEF_PEER_IDX)
return -EINVAL;
return ntb_ndev(ntb)->mw_count;
}
static int amd_ntb_mw_get_align(struct ntb_dev *ntb, int pidx, int idx,
resource_size_t *addr_align,
resource_size_t *size_align,
resource_size_t *size_max)
{
struct amd_ntb_dev *ndev = ntb_ndev(ntb);
int bar;
if (pidx != NTB_DEF_PEER_IDX)
return -EINVAL;
bar = ndev_mw_to_bar(ndev, idx);
if (bar < 0)
return bar;
if (addr_align)
*addr_align = SZ_4K;
if (size_align)
*size_align = 1;
if (size_max)
*size_max = pci_resource_len(ndev->ntb.pdev, bar);
return 0;
}
static int amd_ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int idx,
dma_addr_t addr, resource_size_t size)
{
struct amd_ntb_dev *ndev = ntb_ndev(ntb);
unsigned long xlat_reg, limit_reg = 0;
resource_size_t mw_size;
void __iomem *mmio, *peer_mmio;
u64 base_addr, limit, reg_val;
int bar;
if (pidx != NTB_DEF_PEER_IDX)
return -EINVAL;
bar = ndev_mw_to_bar(ndev, idx);
if (bar < 0)
return bar;
mw_size = pci_resource_len(ntb->pdev, bar);
/* make sure the range fits in the usable mw size */
if (size > mw_size)
return -EINVAL;
mmio = ndev->self_mmio;
peer_mmio = ndev->peer_mmio;
base_addr = pci_resource_start(ntb->pdev, bar);
if (bar != 1) {
xlat_reg = AMD_BAR23XLAT_OFFSET + ((bar - 2) << 2);
limit_reg = AMD_BAR23LMT_OFFSET + ((bar - 2) << 2);
/* Set the limit if supported */
limit = size;
/* set and verify setting the translation address */
write64(addr, peer_mmio + xlat_reg);
reg_val = read64(peer_mmio + xlat_reg);
if (reg_val != addr) {
write64(0, peer_mmio + xlat_reg);
return -EIO;
}
/* set and verify setting the limit */
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/delay.h`, `linux/init.h`, `linux/interrupt.h`, `linux/module.h`, `linux/acpi.h`, `linux/pci.h`, `linux/random.h`.
- Detected declarations: `function ndev_mw_to_bar`, `function amd_ntb_mw_count`, `function amd_ntb_mw_get_align`, `function amd_ntb_mw_set_trans`, `function amd_ntb_get_link_status`, `function amd_link_is_up`, `function amd_ntb_link_is_up`, `function amd_ntb_link_enable`, `function amd_ntb_link_disable`, `function amd_ntb_peer_mw_count`.
- 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.
- 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.