drivers/nvdimm/pfn_devs.c
Source file repositories/reference/linux-study-clean/drivers/nvdimm/pfn_devs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvdimm/pfn_devs.c- Extension
.c- Size
- 22876 bytes
- Lines
- 860
- Domain
- Driver Families
- Bucket
- drivers/nvdimm
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/memremap.hlinux/blkdev.hlinux/device.hlinux/sizes.hlinux/slab.hlinux/fs.hlinux/mm.hnd-core.hpfn.hnd.h
Detected Declarations
function nd_pfn_releasefunction mode_showfunction mode_storefunction align_showfunction nd_pfn_default_alignmentfunction align_storefunction uuid_showfunction uuid_storefunction namespace_showfunction namespace_storefunction resource_showfunction size_showfunction supported_alignments_showfunction is_nd_pfnfunction nd_pfn_clear_memmap_errorsfunction nd_supported_alignmentfunction nd_pfn_validatefunction nd_pfn_probefunction scoped_guardfunction init_altmap_basefunction init_altmap_reservefunction __nvdimm_setup_pfnfunction nd_pfn_initfunction nvdimm_setup_pfnexport to_nd_pfnexport is_nd_pfnexport nd_pfn_validateexport nd_pfn_probeexport nvdimm_setup_pfn
Annotated Snippet
if (bb_present) {
dev_dbg(&nd_pfn->dev, "meta: %llx badblocks at %llx\n",
num_bad, first_bad);
nsoff = ALIGN_DOWN((nd_region->ndr_start
+ (first_bad << 9)) - nsio->res.start,
PAGE_SIZE);
zero_len = ALIGN(num_bad << 9, PAGE_SIZE);
while (zero_len) {
unsigned long chunk = min(zero_len, PAGE_SIZE);
rc = nvdimm_write_bytes(ndns, nsoff, zero_page,
chunk, 0);
if (rc)
break;
zero_len -= chunk;
nsoff += chunk;
}
if (rc) {
dev_err(&nd_pfn->dev,
"error clearing %llx badblocks at %llx\n",
num_bad, first_bad);
return rc;
}
}
} while (bb_present);
return 0;
}
static bool nd_supported_alignment(unsigned long align)
{
int i;
unsigned long supported[MAX_NVDIMM_ALIGN] = { [0] = 0, };
if (align == 0)
return false;
nd_pfn_supported_alignments(supported);
for (i = 0; supported[i]; i++)
if (align == supported[i])
return true;
return false;
}
/**
* nd_pfn_validate - read and validate info-block
* @nd_pfn: fsdax namespace runtime state / properties
* @sig: 'devdax' or 'fsdax' signature
*
* Upon return the info-block buffer contents (->pfn_sb) are
* indeterminate when validation fails, and a coherent info-block
* otherwise.
*/
int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
{
u64 checksum, offset;
struct resource *res;
enum nd_pfn_mode mode;
resource_size_t res_size;
struct nd_namespace_io *nsio;
unsigned long align, start_pad, end_trunc;
struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
struct nd_namespace_common *ndns = nd_pfn->ndns;
const uuid_t *parent_uuid = nd_dev_to_uuid(&ndns->dev);
if (!pfn_sb || !ndns)
return -ENODEV;
if (!is_memory(nd_pfn->dev.parent))
return -ENODEV;
if (nvdimm_read_bytes(ndns, SZ_4K, pfn_sb, sizeof(*pfn_sb), 0))
return -ENXIO;
if (memcmp(pfn_sb->signature, sig, PFN_SIG_LEN) != 0)
return -ENODEV;
checksum = le64_to_cpu(pfn_sb->checksum);
pfn_sb->checksum = 0;
if (checksum != nd_sb_checksum((struct nd_gen_sb *) pfn_sb))
return -ENODEV;
pfn_sb->checksum = cpu_to_le64(checksum);
if (memcmp(pfn_sb->parent_uuid, parent_uuid, 16) != 0)
return -ENODEV;
if (__le16_to_cpu(pfn_sb->version_minor) < 1) {
pfn_sb->start_pad = 0;
pfn_sb->end_trunc = 0;
Annotation
- Immediate include surface: `linux/memremap.h`, `linux/blkdev.h`, `linux/device.h`, `linux/sizes.h`, `linux/slab.h`, `linux/fs.h`, `linux/mm.h`, `nd-core.h`.
- Detected declarations: `function nd_pfn_release`, `function mode_show`, `function mode_store`, `function align_show`, `function nd_pfn_default_alignment`, `function align_store`, `function uuid_show`, `function uuid_store`, `function namespace_show`, `function namespace_store`.
- Atlas domain: Driver Families / drivers/nvdimm.
- 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.