test_debug_virtual.c 933 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <linux/kernel.h>
  2. #include <linux/module.h>
  3. #include <linux/export.h>
  4. #include <linux/mm.h>
  5. #include <linux/vmalloc.h>
  6. #include <linux/slab.h>
  7. #include <linux/sizes.h>
  8. #include <linux/io.h>
  9. #include <asm/page.h>
  10. #ifdef CONFIG_MIPS
  11. #include <asm/bootinfo.h>
  12. #endif
  13. struct foo {
  14. unsigned int bar;
  15. };
  16. struct foo *foo;
  17. static int __init test_debug_virtual_init(void)
  18. {
  19. phys_addr_t pa;
  20. void *va;
  21. va = (void *)VMALLOC_START;
  22. pa = virt_to_phys(va);
  23. pr_info("PA: %pa for VA: 0x%lx\n", &pa, (unsigned long)va);
  24. foo = kzalloc(sizeof(*foo), GFP_KERNEL);
  25. if (!foo)
  26. return -ENOMEM;
  27. pa = virt_to_phys(foo);
  28. va = foo;
  29. pr_info("PA: %pa for VA: 0x%lx\n", &pa, (unsigned long)va);
  30. return 0;
  31. }
  32. module_init(test_debug_virtual_init);
  33. static void __exit test_debug_virtual_exit(void)
  34. {
  35. kfree(foo);
  36. }
  37. module_exit(test_debug_virtual_exit);
  38. MODULE_LICENSE("GPL");
  39. MODULE_DESCRIPTION("Test module for CONFIG_DEBUG_VIRTUAL");