我是靠谱客的博主 调皮流沙,最近开发中收集的这篇文章主要介绍PCIe 共享内存,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述


static int __init shmem_init(void)
    //allocate 10 pages in the kernel memory space as the shared memory  
+-- kmalloc_ptr_master = kmalloc(TOTAL_SMEM_WINDOW_SIZE, GFP_KERNEL)
    //2 pages for master & 2 pages for slave with the start address page aligned
+-- kmalloc_area_master = (int *)((((unsigned long)kmalloc_ptr_master) + PAGE_SIZE - 1) & PAGE_MASK);
+-- kmalloc_area_slave  = (int *) ((char *)kmalloc_area_master + (NPAGES * PAGE_SIZE));
    //creat a charactor device to manage the share memory and 
    //provide a control interface to the user space
+-- alloc_chrdev_region(&shmem_dev, 0, 1, "shmem")
+-- cdev_init(&shmem_cdev, &shmem_fops);
+-- cdev_add(&shmem_cdev, shmem_dev, 1)
    //mark the pages reserved and protect the pages from being swapped out 
+-- SetPageReserved(virt_to_page((unsigned long)kmalloc_area_master));
+-- SetPageReserved(virt_to_page((unsigned long)kmalloc_area_slave) );
    //配置并使能对master/slave memory window的访问.
+-- agni_pcie_window_init();
    +-- INBW_ATTR = (M8572_PCIE_IWAR_EN |                /* Enable */
                     M8572_PCIE_IWAR_TFTINT_LMEM |       /* local bus */
                     M8572_PCIE_IWAR_READTYPE_SNP |      /* read , snoop */
                     M8572_PCIE_IWAR_WRITETYPE_SNP |     /* write, snoop */
                     M8572_PCIE_IWAR_IWS_32K);           /* window size 32K */
        //配置并使能master的inbound memory window
    +-- pci = ioremap((MPC8572_MAP_BASE|MPC8572_PCIE_CTRL_2), MPC8572_PCIE_CTRL_SPACE);
    +-- out_be32(&pci->piw[PCIE_INBW1].piwar, 0);
    +-- out_be32(&pci->piw[PCIE_INBW1].pitar,  virt_to_phys((void *)kmalloc_area_master) >> PAGE_SHIFT);
    +-- out_be32(&pci->piw[PCIE_INBW1].piwbar, virt_to_phys((void *)kmalloc_area_master) >> PAGE_SHIFT);
    +-- out_be32(&pci->piw[PCIE_INBW1].piwar, INBW_ATTR);
        //配置并使能slave的inboud memory window 
    +-- pci = ioremap((MPC8572_MAP_BASE|MPC8572_PCIE_CTRL_3), MPC8572_PCIE_CTRL_SPACE);
    +-- out_be32(&pci->piw[PCIE_INBW1].piwar, 0);
    +-- out_be32(&pci->piw[PCIE_INBW1].pitar,  virt_to_phys((void *)kmalloc_area_slave) >> PAGE_SHIFT);
    +-- out_be32(&pci->piw[PCIE_INBW1].piwbar, virt_to_phys((void *)kmalloc_area_slave) >> PAGE_SHIFT);
    +-- out_be32(&pci->piw[PCIE_INBW1].piwar, INBW_ATTR);



static int shmem_mmap(struct file *filp, struct vm_area_struct *vma)
    //if(vma->vm_pgoff == 0)
+-- shmem_alloc_master(filp, vma);
    +-- long length_master = vma_master->vm_end - vma_master->vm_start;
        //uncached the master memory region allocated
    +-- vma_master->vm_page_prot = pgprot_noncached(vma_master->vm_page_prot);
        //mmap the memory to the user space
    +-- remap_pfn_range(vma_master,
                        vma_master->vm_start,
                        virt_to_phys((void *)kmalloc_area_master) >> PAGE_SHIFT,
                        length_master, vma_master->vm_page_prot)
    //if(vma->vm_pgoff == NPAGES)
+-- shmem_alloc_slave(filp, vma);
    +-- long length_slave = vma_slave->vm_end - vma_slave->vm_start;
        //uncached the master memory region allocated
    +-- vma_slave->vm_page_prot = pgprot_noncached(vma_slave->vm_page_prot);
        //mmap the memory to the user space
    +-- remap_pfn_range(vma_slave,
                        vma_slave->vm_start,
                        virt_to_phys((void *)kmalloc_area_slave) >> PAGE_SHIFT,
                        length_slave, vma_slave->vm_page_prot)

static struct file_operations shmem_fops = {
        ...
        .mmap = shmem_mmap,
        ...
};




最后

以上就是调皮流沙为你收集整理的PCIe 共享内存的全部内容,希望文章能够帮你解决PCIe 共享内存所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部