Chinaunix首页 | 论坛 | 博客
  • 博客访问: 305136
  • 博文数量: 65
  • 博客积分: 185
  • 博客等级: 入伍新兵
  • 技术积分: 609
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-06 21:41
个人简介

好好学习,天天向上

文章分类

全部博文(65)

文章存档

2022年(3)

2021年(25)

2020年(1)

2019年(3)

2016年(2)

2015年(3)

2014年(14)

2013年(7)

2012年(7)

我的朋友

分类: 嵌入式

2021-10-21 15:58:50




点击(此处)折叠或打开

  1. -bash-4.2$ cat drivers/smmu_test/smmu_test.c
  2. #include <linux/init.h>
  3. #include <linux/kernel.h>
  4. #include <linux/module.h>
  5. #include <linux/delay.h>
  6. #include <linux/timer.h>
  7. #include <linux/jiffies.h>
  8. #include <linux/module.h>
  9. #include <linux/debugfs.h>
  10. #include <linux/miscdevice.h>
  11. #include <linux/dma-mapping.h>
  12. #include <linux/of_device.h>
  13. #include <linux/slab.h>
  14. #include <asm/current.h>
  15. #include <linux/sched.h>
  16. #include <linux/err.h>
  17. #include <linux/kthread.h>
  18. #include <linux/iommu.h>


  19. /*
  20. CONFIG_OF_IOMMU
  21. CONFIG_IOMMU_DMA
  22. CONFIG_DMA_API_DEBUG
  23. CONFIG_IOMMU_IO_PGTABLE_LPAE_SELFTEST
  24. */

  25. /*
  26. test {
  27.         compatible = "test_id";
  28.         dma-coherent;
  29.         dma-ranges = <0x0 0x0 0x0 0x0 0x80000000 0x00000000>;
  30.         iommus = <&smmu0 0>;


  31.         status = "okay";
  32. };
  33. */



  34. //#define RESV_PHY_ADDR 0xe0000000
  35. //#define RESV_PHY_SIZE 0x80000000
  36. #define RESV_PHY_ADDR 0x2100000000
  37. #define RESV_PHY_SIZE 0x80000000

  38. unsigned long my_iova = 0x50100000;

  39. static int test_probe(struct platform_device *dev)
  40. {
  41.         int ret;
  42.         phys_addr_t phys_addr;
  43.         size_t size;
  44.         struct iommu_domain *mydomain;

  45.         phys_addr = RESV_PHY_ADDR;
  46.         size = RESV_PHY_SIZE;

  47.         pr_info("dbg_added, probe:%s:%d\n", __FUNCTION__, __LINE__);


  48.         mydomain = iommu_domain_alloc(&platform_bus_type);
  49.         if (mydomain == NULL) {
  50.                 pr_info("dbg_added iommu_domain_alloc error\n");
  51.                 return -1;
  52.         } else {
  53.                 pr_info("dbg_added iommu_domain_alloc ok\n");
  54.         }

  55.         ret = iommu_attach_device(mydomain, &dev->dev);
  56.         if (ret) {
  57.                         pr_info("dbg_added iommu_attach_device error\n");
  58.                         return -1;
  59.         } else {
  60.                 pr_info("dbg_added iommu_attach_device ok\n");
  61.         }

  62.         ret = iommu_map(mydomain, my_iova, phys_addr, size, IOMMU_READ | IOMMU_WRITE);
  63.     if (ret < 0) {
  64.                 pr_info("dbg_added iommu_map error\n");
  65.                 return -1;
  66.         } else {
  67.                 pr_info("dbg_added iommu_map ok\n");
  68.         }

  69.         return 0;
  70. }

  71. static int test_remove(struct platform_device *dev)
  72. {
  73.         return 0;
  74. }

  75. static const struct of_device_id test_of_match[] = {
  76.         { .compatible = "test_id" },
  77.         {}
  78. };

  79. MODULE_DEVICE_TABLE(of, test_of_match);

  80. static struct platform_driver test_platform_driver = {
  81.         .driver = {
  82.                 .name = "smmu-test",
  83.                 .of_match_table = test_of_match,
  84.         },
  85.         .probe = test_probe,
  86.         .remove = test_remove,
  87. };


  88. static int __init test_init(void)
  89. {
  90.         pr_info("dbg_added init module\n");
  91.         pr_info("dbg_added the process is %s pid %i\n", current->comm, current->pid);

  92.         platform_driver_register(&test_platform_driver);

  93.         return 0;
  94. }
  95. static void __exit test_exit(void)
  96. {
  97.         platform_driver_unregister(&test_platform_driver);
  98.         pr_info("dbg_added exit modules\n");
  99. }

  100. MODULE_AUTHOR("cl");
  101. MODULE_LICENSE("Dual BSD/GPL");

  102. module_init(test_init);
  103. module_exit(test_exit);-bash-4.2$

阅读(1050) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~