drivers/pci/access.c
Source file repositories/reference/linux-study-clean/drivers/pci/access.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pci/access.c- Extension
.c- Size
- 16312 bytes
- Lines
- 627
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/pci.hlinux/module.hlinux/slab.hlinux/ioport.hlinux/wait.hpci.h
Detected Declarations
function pci_generic_config_readfunction pci_generic_config_writefunction pci_generic_config_read32function pci_generic_config_write32function RW1Cfunction pci_wait_cfgfunction pci_cfg_access_unlockfunction pci_cfg_access_trylockfunction pci_cfg_access_unlockfunction pcie_cap_versionfunction pcie_cap_has_lnkctlfunction pcie_cap_has_lnkctl2function pcie_cap_has_sltctlfunction pcie_cap_has_rtctlfunction pcie_capability_reg_implementedfunction pcie_capability_read_wordfunction pcie_capability_read_dwordfunction pcie_capability_write_wordfunction pcie_capability_write_dwordfunction pcie_capability_clear_and_set_word_unlockedfunction pcie_capability_clear_and_set_word_lockedfunction pcie_capability_clear_and_set_dwordfunction pci_read_config_bytefunction pci_read_config_wordfunction pci_read_config_dwordfunction pci_write_config_bytefunction pci_write_config_wordfunction pci_write_config_dwordfunction pci_clear_and_set_config_dwordexport pci_bus_read_config_byteexport pci_bus_read_config_wordexport pci_bus_read_config_dwordexport pci_bus_write_config_byteexport pci_bus_write_config_wordexport pci_bus_write_config_dwordexport pci_generic_config_readexport pci_generic_config_writeexport pci_generic_config_read32export pci_generic_config_write32export pci_bus_set_opsexport pci_cfg_access_lockexport pci_cfg_access_trylockexport pci_cfg_access_unlockexport pcie_capability_read_wordexport pcie_capability_read_dwordexport pcie_capability_write_wordexport pcie_capability_write_dwordexport pcie_capability_clear_and_set_word_unlocked
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <linux/pci.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/ioport.h>
#include <linux/wait.h>
#include "pci.h"
/*
* This interrupt-safe spinlock protects all accesses to PCI
* configuration space.
*/
DEFINE_RAW_SPINLOCK(pci_lock);
/*
* Wrappers for all PCI configuration access functions. They just check
* alignment, do locking and call the low-level functions pointed to
* by pci_dev->ops.
*/
#define PCI_byte_BAD 0
#define PCI_word_BAD (pos & 1)
#define PCI_dword_BAD (pos & 3)
#ifdef CONFIG_PCI_LOCKLESS_CONFIG
# define pci_lock_config(f) do { (void)(f); } while (0)
# define pci_unlock_config(f) do { (void)(f); } while (0)
#else
# define pci_lock_config(f) raw_spin_lock_irqsave(&pci_lock, f)
# define pci_unlock_config(f) raw_spin_unlock_irqrestore(&pci_lock, f)
#endif
#define PCI_OP_READ(size, type, len) \
int noinline pci_bus_read_config_##size \
(struct pci_bus *bus, unsigned int devfn, int pos, type *value) \
{ \
unsigned long flags; \
u32 data = 0; \
int res; \
\
if (PCI_##size##_BAD) \
return PCIBIOS_BAD_REGISTER_NUMBER; \
\
pci_lock_config(flags); \
res = bus->ops->read(bus, devfn, pos, len, &data); \
if (res) \
PCI_SET_ERROR_RESPONSE(value); \
else \
*value = (type)data; \
pci_unlock_config(flags); \
\
return res; \
}
#define PCI_OP_WRITE(size, type, len) \
int noinline pci_bus_write_config_##size \
(struct pci_bus *bus, unsigned int devfn, int pos, type value) \
{ \
unsigned long flags; \
int res; \
\
if (PCI_##size##_BAD) \
return PCIBIOS_BAD_REGISTER_NUMBER; \
\
pci_lock_config(flags); \
res = bus->ops->write(bus, devfn, pos, len, value); \
pci_unlock_config(flags); \
\
return res; \
}
PCI_OP_READ(byte, u8, 1)
PCI_OP_READ(word, u16, 2)
PCI_OP_READ(dword, u32, 4)
PCI_OP_WRITE(byte, u8, 1)
PCI_OP_WRITE(word, u16, 2)
PCI_OP_WRITE(dword, u32, 4)
EXPORT_SYMBOL(pci_bus_read_config_byte);
EXPORT_SYMBOL(pci_bus_read_config_word);
EXPORT_SYMBOL(pci_bus_read_config_dword);
EXPORT_SYMBOL(pci_bus_write_config_byte);
EXPORT_SYMBOL(pci_bus_write_config_word);
EXPORT_SYMBOL(pci_bus_write_config_dword);
int pci_generic_config_read(struct pci_bus *bus, unsigned int devfn,
int where, int size, u32 *val)
{
Annotation
- Immediate include surface: `linux/pci.h`, `linux/module.h`, `linux/slab.h`, `linux/ioport.h`, `linux/wait.h`, `pci.h`.
- Detected declarations: `function pci_generic_config_read`, `function pci_generic_config_write`, `function pci_generic_config_read32`, `function pci_generic_config_write32`, `function RW1C`, `function pci_wait_cfg`, `function pci_cfg_access_unlock`, `function pci_cfg_access_trylock`, `function pci_cfg_access_unlock`, `function pcie_cap_version`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: integration 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.