-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathv2p.c
More file actions
34 lines (26 loc) · 809 Bytes
/
Copy pathv2p.c
File metadata and controls
34 lines (26 loc) · 809 Bytes
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
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <asm/io.h>
static int __init v2p_init(void) {
int * my_data = kmalloc(1, GFP_KERNEL);
pr_info("Virtual address of my_data:\t%p\n", my_data);
phys_addr_t phys_addr = virt_to_phys(my_data);
pr_info("Physical address of my_data:\t%pa\n", &phys_addr);
void * virt_addr = phys_to_virt(phys_addr);
pr_info("Back to virtual address:\t\t%p\n", virt_addr);
if (virt_addr == my_data) {
pr_info("SUCCESS: Addresses match!\n");
} else {
pr_info("FAIL: Addresses DO NOT match!\n");
}
kfree(my_data);
return -2;
}
static void __exit v2p_exit(void) {
pr_info("V2P exit\n");
}
module_init(v2p_init);
module_exit(v2p_exit);
MODULE_LICENSE("GPL");