我是靠谱客的博主 调皮流沙,这篇文章主要介绍PCIe 共享内存,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部