include/linux/scatterlist.h
Source file repositories/reference/linux-study-clean/include/linux/scatterlist.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/scatterlist.h- Extension
.h- Size
- 22314 bytes
- Lines
- 721
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/string.hlinux/types.hlinux/bug.hlinux/mm.hasm/io.h
Detected Declarations
struct scatterliststruct sg_tablestruct sg_append_tablestruct sg_page_iterstruct sg_dma_page_iterstruct sg_mapping_iterfunction sg_nextfunction sg_is_chainfunction sg_is_lastfunction sg_assign_pagefunction sg_set_pagefunction sg_set_foliofunction sg_set_buffunction sg_dma_addressfunction sg_chainfunction sg_mark_endfunction sg_unmark_endfunction sg_dma_mark_bus_addressfunction dma_map_sgfunction sg_dma_unmark_bus_addressfunction swiotlb_find_poolfunction sg_dma_mark_swiotlbfunction sg_dma_is_bus_addressfunction sg_dma_mark_bus_addressfunction sg_dma_mark_swiotlbfunction page_addressfunction sg_init_markerfunction sg_alloc_table_from_pagesfunction sg_page_iter_dma_address
Annotated Snippet
struct scatterlist {
unsigned long page_link;
unsigned int offset;
unsigned int length;
dma_addr_t dma_address;
#ifdef CONFIG_NEED_SG_DMA_LENGTH
unsigned int dma_length;
#endif
#ifdef CONFIG_NEED_SG_DMA_FLAGS
unsigned int dma_flags;
#endif
};
/*
* These macros should be used after a dma_map_sg call has been done
* to get bus addresses of each of the SG entries and their lengths.
* You should only work with the number of sg entries dma_map_sg
* returns, or alternatively stop on the first sg_dma_len(sg) which
* is 0.
*/
#define sg_dma_address(sg) ((sg)->dma_address)
#ifdef CONFIG_NEED_SG_DMA_LENGTH
#define sg_dma_len(sg) ((sg)->dma_length)
#else
#define sg_dma_len(sg) ((sg)->length)
#endif
struct sg_table {
struct scatterlist *sgl; /* the list */
unsigned int nents; /* number of mapped entries */
unsigned int orig_nents; /* original size of list */
};
struct sg_append_table {
struct sg_table sgt; /* The scatter list table */
struct scatterlist *prv; /* last populated sge in the table */
unsigned int total_nents; /* Total entries in the table */
};
/*
* Notes on SG table design.
*
* We use the unsigned long page_link field in the scatterlist struct to place
* the page pointer AND encode information about the sg table as well. The two
* lower bits are reserved for this information.
*
* If bit 0 is set, then the page_link contains a pointer to the next sg
* table list. Otherwise the next entry is at sg + 1.
*
* If bit 1 is set, then this sg entry is the last element in a list.
*
* See sg_next().
*
*/
#define SG_CHAIN 0x01UL
#define SG_END 0x02UL
/*
* We overload the LSB of the page pointer to indicate whether it's
* a valid sg entry, or whether it points to the start of a new scatterlist.
* Those low bits are there for everyone! (thanks mason :-)
*/
#define SG_PAGE_LINK_MASK (SG_CHAIN | SG_END)
static inline unsigned int __sg_flags(struct scatterlist *sg)
{
return sg->page_link & SG_PAGE_LINK_MASK;
}
static inline struct scatterlist *sg_chain_ptr(struct scatterlist *sg)
{
return (struct scatterlist *)(sg->page_link & ~SG_PAGE_LINK_MASK);
}
static inline bool sg_is_chain(struct scatterlist *sg)
{
return __sg_flags(sg) & SG_CHAIN;
}
static inline bool sg_is_last(struct scatterlist *sg)
{
return __sg_flags(sg) & SG_END;
}
/**
* sg_next - return the next scatterlist entry in a list
* @sg: The current sg entry
*
Annotation
- Immediate include surface: `linux/string.h`, `linux/types.h`, `linux/bug.h`, `linux/mm.h`, `asm/io.h`.
- Detected declarations: `struct scatterlist`, `struct sg_table`, `struct sg_append_table`, `struct sg_page_iter`, `struct sg_dma_page_iter`, `struct sg_mapping_iter`, `function sg_next`, `function sg_is_chain`, `function sg_is_last`, `function sg_assign_page`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.