当前位置:网站首页>ion_mmap
ion_mmap
2022-06-10 23:57:00 【wmzjzwlzs】
static int ion_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma)
{
struct ion_buffer *buffer = dmabuf->priv;
int ret = 0;
if (!buffer->heap->ops->map_user) {
pr_err("%s: this heap does not define a method for mapping to userspace\n",
__func__);
return -EINVAL;
}
if (!(buffer->flags & ION_FLAG_CACHED))
vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
mutex_lock(&buffer->lock);
/* now map it to userspace */
ret = buffer->heap->ops->map_user(buffer->heap, buffer, vma);
mutex_unlock(&buffer->lock);
if (ret)
pr_err("%s: failure mapping buffer to userspace\n",
__func__);
return ret;
}
int ion_heap_map_user(struct ion_heap *heap, struct ion_buffer *buffer,
struct vm_area_struct *vma)
{
struct sg_table *table = buffer->sg_table;
unsigned long addr = vma->vm_start;
unsigned long offset = vma->vm_pgoff * PAGE_SIZE;
struct scatterlist *sg;
int i;
int ret;
for_each_sg(table->sgl, sg, table->nents, i) {
struct page *page = sg_page(sg);
unsigned long remainder = vma->vm_end - addr;
unsigned long len = sg->length;
if (offset >= sg->length) {
offset -= sg->length;
continue;
} else if (offset) {
page += offset / PAGE_SIZE;
len = sg->length - offset;
offset = 0;
}
len = min(len, remainder);
ret = remap_pfn_range(vma, addr, page_to_pfn(page), len,
vma->vm_page_prot);
if (ret)
return ret;
addr += len;
if (addr >= vma->vm_end)
return 0;
}
return 0;
}
边栏推荐
猜你喜欢

MySQL
![[network planning] 2.2.4 Web cache / proxy server](/img/a8/74a1b44ce4d8b0b1a85043a091a91d.jpg)
[network planning] 2.2.4 Web cache / proxy server

How word removes the header line

AQS explanation of concurrent programming

C语言实现设置桌面壁纸

Alicloud configures SLB (load balancing) instances

Blocking queue - delayedworkqueue source code analysis

How to install mathtype6.9 and related problem solutions in office2016 (word2016)

How to guarantee the quality of real-time data, the cornerstone of the 100 million level search system (Youku Video Search)? v2020

compiler explorer
随机推荐
LeetCode 8. 字符串转换整数 (atoi)(中等、字符串)
How to ensure the sequence of messages, that messages are not lost or consumed repeatedly
[network planning] 2.2.4 Web cache / proxy server
Golang中的深拷贝与浅拷贝
Win11 uninstall widget
扎实的基础知识+正确的方法是快速阅读源码的关键
Detailed explanation of five types of load balancing principle scenarios
STM32下载代码后出现无法再次下载的问题
Locks in sqlserver
Load balancing strategy graphic explanation
Animation
oracle带xy字段值的关系表同步到pg数据库转为几何字段
记录oracle的几个参数 db_files,Cursor_sharing ,open_cursor
一些有的没的闲话
About log traffic monitoring and early warning small project | flask
NVIDIA Jetson之PWM风扇自定义控制
MySql 触发器
Alicloud configures SLB (load balancing) instances
The mystery of number idempotent and perfect square
table_exists_action=append和table_exists_action=truncate