Blame view

lib/test_debug_virtual.c 940 Bytes
e4dace361   Florian Fainelli   lib: add test mod...
1
2
3
4
5
6
7
  #include <linux/kernel.h>
  #include <linux/module.h>
  #include <linux/export.h>
  #include <linux/mm.h>
  #include <linux/vmalloc.h>
  #include <linux/slab.h>
  #include <linux/sizes.h>
4f44e58a5   Christophe Leroy   lib: fix build fa...
8
  #include <linux/io.h>
e4dace361   Florian Fainelli   lib: add test mod...
9
10
11
12
13
14
15
16
17
  
  #include <asm/page.h>
  #ifdef CONFIG_MIPS
  #include <asm/bootinfo.h>
  #endif
  
  struct foo {
  	unsigned int bar;
  };
b15f5f1ae   Colin Ian King   lib/test_debug_vi...
18
  static struct foo *foo;
e4dace361   Florian Fainelli   lib: add test mod...
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
  
  static int __init test_debug_virtual_init(void)
  {
  	phys_addr_t pa;
  	void *va;
  
  	va = (void *)VMALLOC_START;
  	pa = virt_to_phys(va);
  
  	pr_info("PA: %pa for VA: 0x%lx
  ", &pa, (unsigned long)va);
  
  	foo = kzalloc(sizeof(*foo), GFP_KERNEL);
  	if (!foo)
  		return -ENOMEM;
  
  	pa = virt_to_phys(foo);
  	va = foo;
  	pr_info("PA: %pa for VA: 0x%lx
  ", &pa, (unsigned long)va);
  
  	return 0;
  }
  module_init(test_debug_virtual_init);
  
  static void __exit test_debug_virtual_exit(void)
  {
  	kfree(foo);
  }
  module_exit(test_debug_virtual_exit);
  
  MODULE_LICENSE("GPL");
  MODULE_DESCRIPTION("Test module for CONFIG_DEBUG_VIRTUAL");