drivers/xen/grant-table.c
Source file repositories/reference/linux-study-clean/drivers/xen/grant-table.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/xen/grant-table.c- Extension
.c- Size
- 43199 bytes
- Lines
- 1700
- Domain
- Driver Families
- Bucket
- drivers/xen
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/bitmap.hlinux/memblock.hlinux/sched.hlinux/mm.hlinux/slab.hlinux/vmalloc.hlinux/uaccess.hlinux/io.hlinux/delay.hlinux/hardirq.hlinux/workqueue.hlinux/ratelimit.hlinux/moduleparam.hlinux/dma-mapping.hxen/xen.hxen/interface/xen.hxen/page.hxen/grant_table.hxen/interface/memory.hxen/hvc-console.hxen/swiotlb-xen.hxen/balloon.hasm/cpuid/api.hasm/xen/cpuid.hxen/mem-reservation.hasm/xen/hypercall.hasm/xen/interface.hasm/sync_bitops.h
Detected Declarations
struct gnttab_opsstruct unmap_refs_callback_datastruct deferred_entryfunction get_free_entriesfunction get_seq_entry_countfunction get_free_seqfunction get_free_entries_seqfunction do_free_callbacksfunction check_free_callbacksfunction put_free_entry_lockedfunction put_free_entryfunction gnttab_set_freefunction gnttab_update_entry_v1function gnttab_update_entry_v2function gnttab_grant_foreign_access_reffunction gnttab_grant_foreign_accessfunction gnttab_end_foreign_access_ref_v1function gnttab_end_foreign_access_ref_v2function _gnttab_end_foreign_access_reffunction gnttab_end_foreign_access_reffunction gnttab_read_frame_v1function gnttab_read_frame_v2function gnttab_handle_deferredfunction gnttab_add_deferredfunction gnttab_try_end_foreign_accessfunction gnttab_end_foreign_accessfunction gnttab_free_grant_referencefunction gnttab_free_grant_referencesfunction gnttab_free_grant_reference_seqfunction gnttab_alloc_grant_referencesfunction gnttab_alloc_grant_reference_seqfunction gnttab_empty_grant_referencesfunction gnttab_claim_grant_referencefunction gnttab_release_grant_referencefunction gnttab_request_free_callbackfunction gnttab_cancel_free_callbackfunction gnttab_framesfunction grow_gnttab_listfunction __max_nr_grant_framesfunction gnttab_max_grant_framesfunction gnttab_setup_auto_xlat_framesfunction gnttab_free_auto_xlat_framesfunction gnttab_pages_set_privatefunction gnttab_alloc_pagesfunction cache_initfunction cache_emptyfunction cache_enqfunction cache_init
Annotated Snippet
struct gnttab_ops {
/*
* Version of the grant interface.
*/
unsigned int version;
/*
* Grant refs per grant frame.
*/
unsigned int grefs_per_grant_frame;
/*
* Mapping a list of frames for storing grant entries. Frames parameter
* is used to store grant table address when grant table being setup,
* nr_gframes is the number of frames to map grant table. Returning
* GNTST_okay means success and negative value means failure.
*/
int (*map_frames)(xen_pfn_t *frames, unsigned int nr_gframes);
/*
* Release a list of frames which are mapped in map_frames for grant
* entry status.
*/
void (*unmap_frames)(void);
/*
* Introducing a valid entry into the grant table, granting the frame of
* this grant entry to domain for accessing. Ref
* parameter is reference of this introduced grant entry, domid is id of
* granted domain, frame is the page frame to be granted, and flags is
* status of the grant entry to be updated.
*/
void (*update_entry)(grant_ref_t ref, domid_t domid,
unsigned long frame, unsigned flags);
/*
* Stop granting a grant entry to domain for accessing. Ref parameter is
* reference of a grant entry whose grant access will be stopped.
* If the grant entry is currently mapped for reading or writing, just
* return failure(==0) directly and don't tear down the grant access.
* Otherwise, stop grant access for this entry and return success(==1).
*/
int (*end_foreign_access_ref)(grant_ref_t ref);
/*
* Read the frame number related to a given grant reference.
*/
unsigned long (*read_frame)(grant_ref_t ref);
};
struct unmap_refs_callback_data {
struct completion completion;
int result;
};
static const struct gnttab_ops *gnttab_interface;
/* This reflects status of grant entries, so act as a global value. */
static grant_status_t *grstatus;
static struct gnttab_free_callback *gnttab_free_callback_list;
static int gnttab_expand(unsigned int req_entries);
#define RPP (PAGE_SIZE / sizeof(grant_ref_t))
#define SPP (PAGE_SIZE / sizeof(grant_status_t))
static inline grant_ref_t *__gnttab_entry(grant_ref_t entry)
{
return &gnttab_list[(entry) / RPP][(entry) % RPP];
}
/* This can be used as an l-value */
#define gnttab_entry(entry) (*__gnttab_entry(entry))
static int get_free_entries(unsigned count)
{
unsigned long flags;
int ref, rc = 0;
grant_ref_t head;
spin_lock_irqsave(&gnttab_list_lock, flags);
if ((gnttab_free_count < count) &&
((rc = gnttab_expand(count - gnttab_free_count)) < 0)) {
spin_unlock_irqrestore(&gnttab_list_lock, flags);
return rc;
}
ref = head = gnttab_free_head;
gnttab_free_count -= count;
while (count--) {
bitmap_clear(gnttab_free_bitmap, head, 1);
if (gnttab_free_tail_ptr == __gnttab_entry(head))
gnttab_free_tail_ptr = &gnttab_free_head;
if (count)
head = gnttab_entry(head);
Annotation
- Immediate include surface: `linux/bitmap.h`, `linux/memblock.h`, `linux/sched.h`, `linux/mm.h`, `linux/slab.h`, `linux/vmalloc.h`, `linux/uaccess.h`, `linux/io.h`.
- Detected declarations: `struct gnttab_ops`, `struct unmap_refs_callback_data`, `struct deferred_entry`, `function get_free_entries`, `function get_seq_entry_count`, `function get_free_seq`, `function get_free_entries_seq`, `function do_free_callbacks`, `function check_free_callbacks`, `function put_free_entry_locked`.
- Atlas domain: Driver Families / drivers/xen.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.