1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2014 ARM Ltd.
4 */
5 #ifndef __ASM_PTDUMP_H
6 #define __ASM_PTDUMP_H
7
8 #ifdef CONFIG_PTDUMP_CORE
9
10 #include <linux/mm_types.h>
11 #include <linux/seq_file.h>
12 #include <linux/ptdump.h>
13
14
15 struct addr_marker {
16 unsigned long start_address;
17 char *name;
18 };
19
20 struct ptdump_info {
21 struct mm_struct *mm;
22 const struct addr_marker *markers;
23 unsigned long base_addr;
24 };
25
26 struct prot_bits {
27 u64 mask;
28 u64 val;
29 const char *set;
30 const char *clear;
31 };
32
33 struct pg_level {
34 const struct prot_bits *bits;
35 const char *name;
36 size_t num;
37 u64 mask;
38 };
39
40 /*
41 * The page dumper groups page table entries of the same type into a single
42 * description. It uses pg_state to track the range information while
43 * iterating over the pte entries. When the continuity is broken it then
44 * dumps out a description of the range.
45 */
46 struct pg_state {
47 struct ptdump_state ptdump;
48 struct pg_level *pg_level;
49 struct seq_file *seq;
50 const struct addr_marker *marker;
51 unsigned long start_address;
52 int level;
53 u64 current_prot;
54 bool check_wx;
55 unsigned long wx_pages;
56 unsigned long uxn_pages;
57 };
58
59 void ptdump_walk(struct seq_file *s, struct ptdump_info *info);
60 void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
61 u64 val);
62 #ifdef CONFIG_PTDUMP_DEBUGFS
63 #define EFI_RUNTIME_MAP_END DEFAULT_MAP_WINDOW_64
64 void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name);
65 #else
ptdump_debugfs_register(struct ptdump_info * info,const char * name)66 static inline void ptdump_debugfs_register(struct ptdump_info *info,
67 const char *name) { }
68 #endif /* CONFIG_PTDUMP_DEBUGFS */
69 void ptdump_check_wx(void);
70 #else
note_page(void * pt_st,unsigned long addr,int level,u64 val)71 static inline void note_page(void *pt_st, unsigned long addr,
72 int level, u64 val) { }
73 #endif /* CONFIG_PTDUMP_CORE */
74
75 #ifdef CONFIG_DEBUG_WX
76 #define debug_checkwx() ptdump_check_wx()
77 #else
78 #define debug_checkwx() do { } while (0)
79 #endif
80
81 #endif /* __ASM_PTDUMP_H */
82