]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - drivers/misc/tegra-profiler/backtrace.h
misc: tegra-profiler: add unwind reason codes
[sojka/nv-tegra/linux-3.10.git] / drivers / misc / tegra-profiler / backtrace.h
1 /*
2  * drivers/misc/tegra-profiler/backtrace.h
3  *
4  * Copyright (c) 2015, NVIDIA CORPORATION.  All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  */
16
17 #ifndef __QUADD_BACKTRACE_H
18 #define __QUADD_BACKTRACE_H
19
20 #include <linux/mm.h>
21 #include <linux/bitops.h>
22
23 #define QUADD_MAX_STACK_DEPTH           64
24
25 #define QUADD_UNW_TYPES_SIZE \
26         DIV_ROUND_UP(QUADD_MAX_STACK_DEPTH * 4, sizeof(u32) * BITS_PER_BYTE)
27
28 struct quadd_hrt_ctx;
29
30 struct quadd_unw_methods {
31         unsigned int
32                 fp:1,
33                 ut:1,
34                 ut_ce:1,
35                 dwarf:1;
36 };
37
38 struct quadd_callchain {
39         int nr;
40
41         union {
42                 u32 ip_32[QUADD_MAX_STACK_DEPTH];
43                 u64 ip_64[QUADD_MAX_STACK_DEPTH];
44         };
45
46         u32 types[QUADD_UNW_TYPES_SIZE];
47
48         int cs_64;
49
50         struct quadd_unw_methods um;
51
52         unsigned int urc_fp;
53         unsigned int urc_ut;
54         unsigned int urc_dwarf;
55
56         unsigned long curr_sp;
57         unsigned long curr_fp;
58         unsigned long curr_fp_thumb;
59         unsigned long curr_pc;
60
61         struct quadd_hrt_ctx *hrt;
62 };
63
64 struct quadd_ctx;
65 struct pt_regs;
66
67 unsigned int
68 quadd_get_user_callchain(struct pt_regs *regs,
69                          struct quadd_callchain *cc_data,
70                          struct quadd_ctx *ctx,
71                          struct task_struct *task);
72
73 int
74 quadd_callchain_store(struct quadd_callchain *cc,
75                       unsigned long ip, unsigned int type);
76
77 unsigned long
78 quadd_user_stack_pointer(struct pt_regs *regs);
79
80 unsigned long
81 quadd_get_user_frame_pointer(struct pt_regs *regs);
82
83 unsigned long
84 quadd_user_link_register(struct pt_regs *regs);
85
86 static inline int
87 is_vma_addr(unsigned long addr, struct vm_area_struct *vma,
88             unsigned long nbytes)
89 {
90         return  vma &&
91                 addr >= vma->vm_start &&
92                 addr < vma->vm_end - nbytes;
93 }
94
95 static inline int
96 validate_pc_addr(unsigned long addr, unsigned long nbytes)
97 {
98         return addr && addr < TASK_SIZE - nbytes;
99 }
100
101 static inline int
102 validate_stack_addr(unsigned long addr,
103                     struct vm_area_struct *vma,
104                     unsigned long nbytes)
105 {
106         if (addr & 0x03)
107                 return 0;
108
109         return is_vma_addr(addr, vma, nbytes);
110 }
111
112 #endif  /* __QUADD_BACKTRACE_H */