-
Notifications
You must be signed in to change notification settings - Fork 11
/
hw_breakpoint_until.c
139 lines (125 loc) · 2.89 KB
/
hw_breakpoint_until.c
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <linux/version.h>
#include "ext_hw_breakpoint.h"
#include "hw_breakpoint_until.h"
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 72)
#define VM_LAZY_FREE 0x02
#define VM_VM_AREA 0x04
#endif
#ifdef HW_PROC_CMD_DEBUG
static void print_cmd_params(int argc, char *argv[])
{
int loop = 0;
for (loop = 0; loop < argc; loop++) {
pr_info("loop:%d, %s\n", loop, argv[loop]);
}
}
#endif
void process_cmd_string(char *p_buf, int *p_argc, char *p_argv[])
{
int i_argc;
char *p_tmp = p_buf;
p_argv[0] = p_buf;
i_argc = 1;
while (*p_tmp) {
if (' ' == *p_tmp) {
*p_tmp = '\0';
p_argv[i_argc++] = p_tmp + 1;
}
p_tmp++;
}
*p_argc = i_argc;
#ifdef HW_PROC_CMD_DEBUG
print_cmd_params(*pArgc, pArgv);
#endif
}
void free_iophys_info(iophys_info *info)
{
iophys_info *node = NULL, *next = NULL;
if (info) {
list_for_each_entry_safe (node, next, &info->list, list) {
list_del(&node->list);
kfree(node);
}
kfree(info);
}
}
EXPORT_SYMBOL_GPL(free_iophys_info);
iophys_info *get_iophys_info(u64 addr)
{
struct vmap_area *va = NULL;
struct vm_struct *area = NULL;
struct vm_struct *next = NULL;
iophys_info *head = NULL;
iophys_info *node = NULL;
if (!HW_SYMS_VAL(vmap_area_lock) || !HW_SYMS_VAL(vmap_area_lock)) {
pr_info("vmap_area_list or vmap_area_lock is NULL, can not get virt");
return head;
}
spin_lock(HW_SYMS_VAL(vmap_area_lock));
list_for_each_entry (va, HW_SYMS_VAL(vmap_area_list), list) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 72)
if (!(va->flags & VM_VM_AREA)) {
continue;
}
#endif
if (!va) {
continue;
}
area = va->vm;
if (!area) {
continue;
}
if (!(area->flags & VM_IOREMAP) ||
area->flags & VM_UNINITIALIZED) {
continue;
}
smp_rmb();
/*If you find the I/O address, check whether the I/O address you want to query is within the I/O address range*/
next = area;
while (next) {
if (next->phys_addr && next->size) {
/*The IO address to be queried is within its range*/
if (addr >= next->phys_addr &&
addr < next->phys_addr + next->size) {
/*find it*/
if (head == NULL) {
head = kzalloc(
sizeof(iophys_info),
GFP_KERNEL);
if (head == NULL) {
goto err;
}
INIT_LIST_HEAD(&head->list);
head->area = *next;
head->virt_addr =
(u64)next->addr + addr -
next->phys_addr;
}
node = kzalloc(sizeof(iophys_info),
GFP_KERNEL);
if (node == NULL) {
goto free;
}
INIT_LIST_HEAD(&node->list);
node->area = *next;
node->virt_addr = (u64)next->addr +
addr -
next->phys_addr;
list_add_tail(&node->list, &head->list);
}
}
next = next->next;
if (next == area) {
break;
}
}
}
spin_unlock(HW_SYMS_VAL(vmap_area_lock));
return head;
free:
free_iophys_info(head);
err:
spin_unlock(HW_SYMS_VAL(vmap_area_lock));
return NULL;
}
EXPORT_SYMBOL_GPL(get_iophys_info);