当前位置: 首页 > news >正文

30岁做网站运营今天发生的重大新闻

30岁做网站运营,今天发生的重大新闻,官网模板源码,做美图 网站有哪些东西一、前言 我们学习了如何使用 alloc_page() 方式来分配内存#xff0c;但是该驱动只能分配1个PAGE_SIZE。本篇我们将在上一篇的基础上#xff0c;实现一个简化版的ION驱动#xff0c;以此来实现任意 size 大小的内存分配。 二、准备 为了和 kernel 标准 ion 驱动兼容但是该驱动只能分配1个PAGE_SIZE。本篇我们将在上一篇的基础上实现一个简化版的ION驱动以此来实现任意 size 大小的内存分配。 二、准备 为了和 kernel 标准 ion 驱动兼容本篇引用了 driver/staging/android/uapi/ion.h 头文件目的是为了方便 userspace 直接使用 struct ion_allocation_data 和 ION_IOC_ALLOC 宏 struct ion_allocation_data {__u64 len;__u32 heap_id_mask;__u32 flags;__u32 fd;__u32 unused; };#define ION_IOC_MAGIC I #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \struct ion_allocation_data)本篇 ion 驱动只使用 ion_allocation_data 结构体中的 len 和 fd 这两个元素其它元素不做处理。 三、示例 exporter-ion.c #include linux/dma-buf.h #include linux/highmem.h #include linux/module.h #include linux/slab.h #include linux/miscdevice.hstruct ion_allocation_data {__u64 len;__u32 heap_id_mask;__u32 flags;__u32 fd;__u32 unused; };#define ION_IOC_MAGIC I #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \struct ion_allocation_data)struct ion_data {int npages;struct page *pages[]; };static int ion_attach(struct dma_buf *dmabuf, struct device *dev,struct dma_buf_attachment *attachment) {pr_info(dmabuf attach device: %s\n, dev_name(dev));return 0; }static void ion_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attachment) {pr_info(dmabuf detach device: %s\n, dev_name(attachment-dev)); }static struct sg_table *ion_map_dma_buf(struct dma_buf_attachment *attachment,enum dma_data_direction dir) {struct ion_data *data attachment-dmabuf-priv;struct sg_table *table;struct scatterlist *sg;int i;table kmalloc(sizeof(*table), GFP_KERNEL);sg_alloc_table(table, data-npages, GFP_KERNEL);sg table-sgl;for (i 0; i data-npages; i) {sg_set_page(sg, data-pages[i], PAGE_SIZE, 0);sg sg_next(sg);}dma_map_sg(NULL, table-sgl, table-nents, dir);return table; }static void ion_unmap_dma_buf(struct dma_buf_attachment *attachment,struct sg_table *table,enum dma_data_direction dir) {dma_unmap_sg(NULL, table-sgl, table-nents, dir);sg_free_table(table);kfree(table); }static void ion_release(struct dma_buf *dma_buf) {struct ion_data *data dma_buf-priv;int i;pr_info(dmabuf release\n);for (i 0; i data-npages; i)put_page(data-pages[i]);kfree(data); } static void *ion_vmap(struct dma_buf *dma_buf) {struct ion_data *data dma_buf-priv;return vm_map_ram(data-pages, data-npages, 0, PAGE_KERNEL); }static void ion_vunmap(struct dma_buf *dma_buf, void *vaddr) {struct ion_data *data dma_buf-priv;vm_unmap_ram(vaddr, data-npages); }static int ion_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma) {struct ion_data *data dma_buf-priv;unsigned long vm_start vma-vm_start;int i;for (i 0; i data-npages; i) {remap_pfn_range(vma, vm_start, page_to_pfn(data-pages[i]),PAGE_SIZE, vma-vm_page_prot);vm_start PAGE_SIZE;}return 0; }static int ion_begin_cpu_access(struct dma_buf *dmabuf,enum dma_data_direction dir) {struct dma_buf_attachment *attachment;struct sg_table *table;attachment list_first_entry(dmabuf-attachments, struct dma_buf_attachment, node);table attachment-sgt;dma_sync_sg_for_cpu(NULL, table-sgl, table-nents, dir);return 0; }static int ion_end_cpu_access(struct dma_buf *dmabuf,enum dma_data_direction dir) {struct dma_buf_attachment *attachment;struct sg_table *table;attachment list_first_entry(dmabuf-attachments, struct dma_buf_attachment, node);table attachment-sgt;dma_sync_sg_for_device(NULL, table-sgl, table-nents, dir);return 0; }static const struct dma_buf_ops exp_dmabuf_ops {.attach ion_attach,.detach ion_detach,.map_dma_buf ion_map_dma_buf,.unmap_dma_buf ion_unmap_dma_buf,.release ion_release,.mmap ion_mmap,.vmap ion_vmap,.vunmap ion_vunmap,.begin_cpu_access ion_begin_cpu_access,.end_cpu_access ion_end_cpu_access, }; static struct dma_buf *ion_alloc(size_t size) {DEFINE_DMA_BUF_EXPORT_INFO(exp_info);struct dma_buf *dmabuf;struct ion_data *data;int i, npages;npages PAGE_ALIGN(size) / PAGE_SIZE;data kmalloc(sizeof(*data) npages * sizeof(struct page *),GFP_KERNEL);data-npages npages;for (i 0; i npages; i)data-pages[i] alloc_page(GFP_KERNEL);exp_info.ops exp_dmabuf_ops;exp_info.size npages * PAGE_SIZE;exp_info.flags O_CLOEXEC;exp_info.priv data;dmabuf dma_buf_export(exp_info);return dmabuf; }static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) {struct dma_buf *dmabuf;struct ion_allocation_data alloc_data;/* currently just only support ION_IOC_ALLOC ioctl */if (cmd ! ION_IOC_ALLOC)return -EINVAL;copy_from_user(alloc_data, (void __user *)arg, sizeof(alloc_data));dmabuf ion_alloc(alloc_data.len);alloc_data.fd dma_buf_fd(dmabuf, O_CLOEXEC);copy_to_user((void __user *)arg, alloc_data, sizeof(alloc_data));return 0; }static struct file_operations ion_fops {.owner THIS_MODULE,.unlocked_ioctl ion_ioctl, };static struct miscdevice mdev {.minor MISC_DYNAMIC_MINOR,.name ion,.fops ion_fops, };static int __init ion_init(void) {return misc_register(mdev); }static void __exit ion_exit(void) {misc_deregister(mdev); }module_init(ion_init); module_exit(ion_exit); 从上面可以看出任意大小的参数在驱动中就是for循环申请页。因为申请的内存不一定时连续物理内存所以使用sg table . 应用程序 ion_test.c #include string.h #include stdio.h #include stdlib.h #include errno.h #include fcntl.h #include unistd.h #include sys/types.h #include sys/stat.h #include sys/ioctl.hstruct ion_allocation_data {__u64 len;__u32 heap_id_mask;__u32 flags;__u32 fd;__u32 unused; };#define PAGE_SIZE 4096int main(int argc, char *argv[]) {int fd;struct ion_allocation_data alloc_data;fd open(/dev/ion, O_RDWR);alloc_data.len 3 * PAGE_SIZE;ioctl(fd, ION_IOC_ALLOC, alloc_data);printf(ion alloc success: size %llu, dmabuf_fd %u\n,alloc_data.len, alloc_data.fd);close(fd);return 0; }该应用程序通过 ION_IOC_ALLOC ioctl 请求分配了3个 page 的物理 buffer如果底层驱动分配成功则会将该 dma-buf 所对应的 fd 返回给应用程序以便后续执行 mmap 操作或将 fd 传给其它模块。 需要注意的是这里的3个 pages 是通过3次调用 alloc_page() 来分配的因此每个 page 之间可能是不连续的也可以近似的认为该 ion 驱动分配的 buffer 属于 ION_HEAP_TYPE_SYSTEM。如果要分配物理连续的 pages请使用 alloc_pages() 进行分配。 上面的驱动中通过变长数组实现虚拟地址连续但是物理地址不一定连续的方法。
http://www.hkea.cn/news/14290807/

相关文章:

  • 河北省城乡建设培训网官方网站抖音流量推广神器软件
  • 网站建设空间多大网站后台不显示验证码
  • 南阳做个网站多少钱上海网站建设开发电话
  • 北京网站建设推seo优化技巧有哪些
  • 哈尔滨智能建站模板郑州做网站建设哪家好
  • 用jsp做婚纱网站的流程海会主机做的网站都能干什么的
  • 有做门窗找活的网站吗网站建设万户
  • 网站建设百度认证图片企业做什么需要有网站
  • 网站商品台管理系统做网站为什么能挣钱
  • 国外免费空间网站申请网站版面布局结构图
  • 大连网站关键词推广html5网站搭建
  • 商城网站建设信息免费站推广网站2022
  • 头条网站收录提交入口互联网保险中介平台
  • 四川省建设厅申报网站南宁模板建站
  • 成都网站seo诊断石材企业网站源码
  • 百度云注册域名可以做网站明码玉环哪里有做网站
  • 汽车o2o网站建设国外代理ip地址 免费
  • 南宁企业网站建设制作如何熟悉网站项目的逻辑
  • dede搭建网站教程supercell账号注册网站
  • 在新西兰做兼职的网站网络营销专业好不好
  • dedecms 门户网站查看wordpress密码破解
  • 做运营的网站网易企业邮箱pop3设置
  • 阿里巴巴网站首页怎么制作广告标识标牌制作公司
  • 张家港建网站公司linux 网站备份
  • 商城网站有什么好处wordpress添加侧栏
  • 加网络网站建设工作室网站建设 app
  • 整站外包优化公司设计网站的公司
  • 化工网站建站模板可以做试题的网站
  • discuz建站流程他达拉非的副作用和危害
  • 手机网站设计公司立找亿企邦网站建设中iis