lib/iomap.c
Source file repositories/reference/linux-study-clean/lib/iomap.c
File Facts
- System
- Linux kernel
- Corpus path
lib/iomap.c- Extension
.c- Size
- 11312 bytes
- Lines
- 430
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- 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/pci.hlinux/io.hlinux/kmsan-checks.hlinux/export.h
Detected Declarations
function addressesfunction ioread8function ioread16function ioread16befunction ioread32function ioread32befunction pio_read64_lo_hifunction pio_read64_hi_lofunction pio_read64be_lo_hifunction pio_read64be_hi_lofunction __ioread64_lo_hifunction __ioread64_hi_lofunction __ioread64be_lo_hifunction __ioread64be_hi_lofunction iowrite8function iowrite16function iowrite16befunction iowrite32function iowrite32befunction pio_write64_lo_hifunction pio_write64_hi_lofunction pio_write64be_lo_hifunction pio_write64be_hi_lofunction __iowrite64_lo_hifunction __iowrite64_hi_lofunction __iowrite64be_lo_hifunction __iowrite64be_hi_lofunction mmio_insbfunction mmio_inswfunction mmio_inslfunction mmio_outsbfunction mmio_outswfunction mmio_outslfunction ioread8_repfunction ioread16_repfunction ioread32_repfunction iowrite8_repfunction iowrite16_repfunction iowrite32_repfunction ioport_unmapfunction pci_iounmapexport ioread8export ioread16export ioread16beexport ioread32export ioread32beexport __ioread64_lo_hiexport __ioread64_hi_lo
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Implement the default iomap interfaces
*
* (C) Copyright 2004 Linus Torvalds
*/
#include <linux/pci.h>
#include <linux/io.h>
#include <linux/kmsan-checks.h>
#include <linux/export.h>
/*
* Read/write from/to an (offsettable) iomem cookie. It might be a PIO
* access or a MMIO access, these functions don't care. The info is
* encoded in the hardware mapping set up by the mapping functions
* (or the cookie itself, depending on implementation and hw).
*
* The generic routines don't assume any hardware mappings, and just
* encode the PIO/MMIO as part of the cookie. They coldly assume that
* the MMIO IO mappings are not in the low address range.
*
* Architectures for which this is not true can't use this generic
* implementation and should do their own copy.
*/
#ifndef HAVE_ARCH_PIO_SIZE
/*
* We encode the physical PIO addresses (0-0xffff) into the
* pointer by offsetting them with a constant (0x10000) and
* assuming that all the low addresses are always PIO. That means
* we can do some sanity checks on the low bits, and don't
* need to just take things for granted.
*/
#define PIO_OFFSET 0x10000UL
#define PIO_MASK 0x0ffffUL
#define PIO_RESERVED 0x40000UL
#endif
static void bad_io_access(unsigned long port, const char *access)
{
static int count = 10;
if (count) {
count--;
WARN(1, KERN_ERR "Bad IO access at port %#lx (%s)\n", port, access);
}
}
/*
* Ugly macros are a way of life.
*/
#define IO_COND(addr, is_pio, is_mmio) do { \
unsigned long port = (unsigned long __force)addr; \
if (port >= PIO_RESERVED) { \
is_mmio; \
} else if (port > PIO_OFFSET) { \
port &= PIO_MASK; \
is_pio; \
} else \
bad_io_access(port, #is_pio ); \
} while (0)
#ifndef pio_read16be
#define pio_read16be(port) swab16(inw(port))
#define pio_read32be(port) swab32(inl(port))
#endif
#ifndef mmio_read16be
#define mmio_read16be(addr) swab16(readw(addr))
#define mmio_read32be(addr) swab32(readl(addr))
#define mmio_read64be(addr) swab64(readq(addr))
#endif
/*
* Here and below, we apply __no_kmsan_checks to functions reading data from
* hardware, to ensure that KMSAN marks their return values as initialized.
*/
__no_kmsan_checks
unsigned int ioread8(const void __iomem *addr)
{
IO_COND(addr, return inb(port), return readb(addr));
return 0xff;
}
__no_kmsan_checks
unsigned int ioread16(const void __iomem *addr)
{
IO_COND(addr, return inw(port), return readw(addr));
return 0xffff;
}
__no_kmsan_checks
Annotation
- Immediate include surface: `linux/pci.h`, `linux/io.h`, `linux/kmsan-checks.h`, `linux/export.h`.
- Detected declarations: `function addresses`, `function ioread8`, `function ioread16`, `function ioread16be`, `function ioread32`, `function ioread32be`, `function pio_read64_lo_hi`, `function pio_read64_hi_lo`, `function pio_read64be_lo_hi`, `function pio_read64be_hi_lo`.
- Atlas domain: Kernel Services / lib.
- 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.