drivers/infiniband/sw/rdmavt/mmap.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/sw/rdmavt/mmap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/sw/rdmavt/mmap.c- Extension
.c- Size
- 4559 bytes
- Lines
- 182
- Domain
- Driver Families
- Bucket
- drivers/infiniband
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/slab.hlinux/vmalloc.hlinux/mm.hrdma/uverbs_ioctl.hmmap.h
Detected Declarations
function Copyrightfunction rvt_release_mmap_infofunction rvt_vma_openfunction rvt_vma_closefunction rvt_mmapfunction rvt_update_mmap_info
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/*
* Copyright(c) 2016 Intel Corporation.
*/
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/mm.h>
#include <rdma/uverbs_ioctl.h>
#include "mmap.h"
/* number of reserved mmaps for the driver */
#define MMAP_RESERVED 256
/* start point for dynamic offsets */
#define MMAP_OFFSET_START (MMAP_RESERVED * PAGE_SIZE)
/**
* rvt_mmap_init - init link list and lock for mem map
* @rdi: rvt dev struct
*/
void rvt_mmap_init(struct rvt_dev_info *rdi)
{
INIT_LIST_HEAD(&rdi->pending_mmaps);
spin_lock_init(&rdi->pending_lock);
rdi->mmap_offset = MMAP_OFFSET_START;
spin_lock_init(&rdi->mmap_offset_lock);
}
/**
* rvt_release_mmap_info - free mmap info structure
* @ref: a pointer to the kref within struct rvt_mmap_info
*/
void rvt_release_mmap_info(struct kref *ref)
{
struct rvt_mmap_info *ip =
container_of(ref, struct rvt_mmap_info, ref);
struct rvt_dev_info *rdi = ib_to_rvt(ip->context->device);
spin_lock_irq(&rdi->pending_lock);
list_del(&ip->pending_mmaps);
spin_unlock_irq(&rdi->pending_lock);
vfree(ip->obj);
kfree(ip);
}
static void rvt_vma_open(struct vm_area_struct *vma)
{
struct rvt_mmap_info *ip = vma->vm_private_data;
kref_get(&ip->ref);
}
static void rvt_vma_close(struct vm_area_struct *vma)
{
struct rvt_mmap_info *ip = vma->vm_private_data;
kref_put(&ip->ref, rvt_release_mmap_info);
}
static const struct vm_operations_struct rvt_vm_ops = {
.open = rvt_vma_open,
.close = rvt_vma_close,
};
/**
* rvt_mmap - create a new mmap region
* @context: the IB user context of the process making the mmap() call
* @vma: the VMA to be initialized
*
* Return: zero if the mmap is OK. Otherwise, return an errno.
*/
int rvt_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
{
struct rvt_dev_info *rdi = ib_to_rvt(context->device);
unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
unsigned long size = vma->vm_end - vma->vm_start;
struct rvt_mmap_info *ip, *pp;
int ret = -EINVAL;
/* call driver if in reserved range */
if (offset < MMAP_OFFSET_START) {
if (rdi->driver_f.mmap)
return rdi->driver_f.mmap(context, vma);
return -EINVAL;
}
/*
* Search the device's list of objects waiting for a mmap call.
* Normally, this list is very short since a call to create a
Annotation
- Immediate include surface: `linux/slab.h`, `linux/vmalloc.h`, `linux/mm.h`, `rdma/uverbs_ioctl.h`, `mmap.h`.
- Detected declarations: `function Copyright`, `function rvt_release_mmap_info`, `function rvt_vma_open`, `function rvt_vma_close`, `function rvt_mmap`, `function rvt_update_mmap_info`.
- Atlas domain: Driver Families / drivers/infiniband.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.