arch/powerpc/lib/pmem.c
Source file repositories/reference/linux-study-clean/arch/powerpc/lib/pmem.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/lib/pmem.c- Extension
.c- Size
- 2369 bytes
- Lines
- 89
- Domain
- Architecture Layer
- Bucket
- arch/powerpc
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
Dependency Surface
linux/string.hlinux/export.hlinux/uaccess.hlinux/libnvdimm.hasm/cacheflush.h
Detected Declarations
function Copyrightfunction __flush_pmem_rangefunction clean_pmem_rangefunction flush_pmem_rangefunction arch_wb_cache_pmemfunction arch_invalidate_pmemfunction copy_from_user_flushcachefunction memcpy_flushcacheexport arch_wb_cache_pmemexport arch_invalidate_pmemexport memcpy_flushcache
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright(c) 2017 IBM Corporation. All rights reserved.
*/
#include <linux/string.h>
#include <linux/export.h>
#include <linux/uaccess.h>
#include <linux/libnvdimm.h>
#include <asm/cacheflush.h>
static inline void __clean_pmem_range(unsigned long start, unsigned long stop)
{
unsigned long shift = l1_dcache_shift();
unsigned long bytes = l1_dcache_bytes();
void *addr = (void *)(start & ~(bytes - 1));
unsigned long size = stop - (unsigned long)addr + (bytes - 1);
unsigned long i;
for (i = 0; i < size >> shift; i++, addr += bytes)
asm volatile(PPC_DCBSTPS(%0, %1): :"i"(0), "r"(addr): "memory");
}
static inline void __flush_pmem_range(unsigned long start, unsigned long stop)
{
unsigned long shift = l1_dcache_shift();
unsigned long bytes = l1_dcache_bytes();
void *addr = (void *)(start & ~(bytes - 1));
unsigned long size = stop - (unsigned long)addr + (bytes - 1);
unsigned long i;
for (i = 0; i < size >> shift; i++, addr += bytes)
asm volatile(PPC_DCBFPS(%0, %1): :"i"(0), "r"(addr): "memory");
}
static inline void clean_pmem_range(unsigned long start, unsigned long stop)
{
if (cpu_has_feature(CPU_FTR_ARCH_207S))
return __clean_pmem_range(start, stop);
}
static inline void flush_pmem_range(unsigned long start, unsigned long stop)
{
if (cpu_has_feature(CPU_FTR_ARCH_207S))
return __flush_pmem_range(start, stop);
}
/*
* CONFIG_ARCH_HAS_PMEM_API symbols
*/
void arch_wb_cache_pmem(void *addr, size_t size)
{
unsigned long start = (unsigned long) addr;
clean_pmem_range(start, start + size);
}
EXPORT_SYMBOL_GPL(arch_wb_cache_pmem);
void arch_invalidate_pmem(void *addr, size_t size)
{
unsigned long start = (unsigned long) addr;
flush_pmem_range(start, start + size);
}
EXPORT_SYMBOL_GPL(arch_invalidate_pmem);
/*
* CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE symbols
*/
size_t copy_from_user_flushcache(void *dest, const void __user *src,
size_t size)
{
unsigned long not_copied, start = (unsigned long) dest;
src = mask_user_address(src);
not_copied = __copy_from_user(dest, src, size);
clean_pmem_range(start, start + size);
return not_copied;
}
void memcpy_flushcache(void *dest, const void *src, size_t size)
{
unsigned long start = (unsigned long) dest;
memcpy(dest, src, size);
clean_pmem_range(start, start + size);
}
EXPORT_SYMBOL(memcpy_flushcache);
Annotation
- Immediate include surface: `linux/string.h`, `linux/export.h`, `linux/uaccess.h`, `linux/libnvdimm.h`, `asm/cacheflush.h`.
- Detected declarations: `function Copyright`, `function __flush_pmem_range`, `function clean_pmem_range`, `function flush_pmem_range`, `function arch_wb_cache_pmem`, `function arch_invalidate_pmem`, `function copy_from_user_flushcache`, `function memcpy_flushcache`, `export arch_wb_cache_pmem`, `export arch_invalidate_pmem`.
- Atlas domain: Architecture Layer / arch/powerpc.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.