drivers/pci/rebar.c
Source file repositories/reference/linux-study-clean/drivers/pci/rebar.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pci/rebar.c- Extension
.c- Size
- 8159 bytes
- Lines
- 313
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bits.hlinux/bitfield.hlinux/bitops.hlinux/errno.hlinux/export.hlinux/ioport.hlinux/log2.hlinux/pci.hlinux/sizes.hlinux/types.hpci.h
Detected Declarations
function pci_rebar_bytes_to_sizefunction pci_rebar_size_to_bytesfunction pci_rebar_initfunction pci_rebar_find_posfunction pci_rebar_get_possible_sizesfunction pci_rebar_size_supportedfunction pci_rebar_get_max_sizefunction pci_rebar_get_current_sizefunction pci_rebar_set_sizefunction pci_restore_rebar_statefunction pci_resize_is_memory_decoding_enabledfunction pci_resize_resource_set_sizefunction pci_resize_resourceexport pci_rebar_bytes_to_sizeexport pci_rebar_size_to_bytesexport pci_rebar_get_possible_sizesexport pci_rebar_size_supportedexport pci_rebar_get_max_sizeexport pci_resize_resource
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* PCI Resizable BAR Extended Capability handling.
*/
#include <linux/bits.h>
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/errno.h>
#include <linux/export.h>
#include <linux/ioport.h>
#include <linux/log2.h>
#include <linux/pci.h>
#include <linux/sizes.h>
#include <linux/types.h>
#include "pci.h"
#define PCI_REBAR_MIN_SIZE ((resource_size_t)SZ_1M)
/**
* pci_rebar_bytes_to_size - Convert size in bytes to PCI BAR Size
* @bytes: size in bytes
*
* Convert size in bytes to encoded BAR Size in Resizable BAR Capability
* (PCIe r6.2, sec. 7.8.6.3).
*
* Return: encoded BAR Size as defined in the PCIe spec (0=1MB, 31=128TB)
*/
int pci_rebar_bytes_to_size(u64 bytes)
{
int rebar_minsize = ilog2(PCI_REBAR_MIN_SIZE);
bytes = roundup_pow_of_two(bytes);
return max(ilog2(bytes), rebar_minsize) - rebar_minsize;
}
EXPORT_SYMBOL_GPL(pci_rebar_bytes_to_size);
/**
* pci_rebar_size_to_bytes - Convert encoded BAR Size to size in bytes
* @size: encoded BAR Size as defined in the PCIe spec (0=1MB, 31=128TB)
*
* Return: BAR size in bytes
*/
resource_size_t pci_rebar_size_to_bytes(int size)
{
return 1ULL << (size + ilog2(PCI_REBAR_MIN_SIZE));
}
EXPORT_SYMBOL_GPL(pci_rebar_size_to_bytes);
void pci_rebar_init(struct pci_dev *pdev)
{
pdev->rebar_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR);
}
/**
* pci_rebar_find_pos - find position of resize control reg for BAR
* @pdev: PCI device
* @bar: BAR to find
*
* Helper to find the position of the control register for a BAR.
*
* Return:
* * %-ENOTSUPP if resizable BARs are not supported at all,
* * %-ENOENT if no control register for the BAR could be found.
*/
static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
{
unsigned int pos, nbars, i;
u32 ctrl;
if (pci_resource_is_iov(bar)) {
pos = pci_iov_vf_rebar_cap(pdev);
bar = pci_resource_num_to_vf_bar(bar);
} else {
pos = pdev->rebar_cap;
}
if (!pos)
return -ENOTSUPP;
pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
nbars = FIELD_GET(PCI_REBAR_CTRL_NBAR_MASK, ctrl);
for (i = 0; i < nbars; i++, pos += 8) {
int bar_idx;
pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
bar_idx = FIELD_GET(PCI_REBAR_CTRL_BAR_IDX, ctrl);
Annotation
- Immediate include surface: `linux/bits.h`, `linux/bitfield.h`, `linux/bitops.h`, `linux/errno.h`, `linux/export.h`, `linux/ioport.h`, `linux/log2.h`, `linux/pci.h`.
- Detected declarations: `function pci_rebar_bytes_to_size`, `function pci_rebar_size_to_bytes`, `function pci_rebar_init`, `function pci_rebar_find_pos`, `function pci_rebar_get_possible_sizes`, `function pci_rebar_size_supported`, `function pci_rebar_get_max_size`, `function pci_rebar_get_current_size`, `function pci_rebar_set_size`, `function pci_restore_rebar_state`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: integration implementation candidate.
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.