summaryrefstree
path: root/kernel/include/linux/rkp_entry.h
blob: f32d47204eaec99ab00f4b5e68edccd8a0e66d8b (plain)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
 *  Copyright (c) 2014 Samsung Electronics Co., Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#ifndef _RKP_ENTRY_H
#define _RKP_ENTRY_H

#ifndef __ASSEMBLY__
#define RKP_PREFIX  UL(0x83800000)
#define RKP_CMDID(CMD_ID)  ((UL(CMD_ID) << 12 ) | RKP_PREFIX)

#define RKP_PGD_SET  RKP_CMDID(0x21)
#define RKP_PMD_SET  RKP_CMDID(0x22)
#define RKP_PTE_SET  RKP_CMDID(0x23)
#define RKP_PGD_FREE RKP_CMDID(0x24)
#define RKP_PGD_NEW  RKP_CMDID(0x25)

#define RKP_INIT	 RKP_CMDID(0)
#define RKP_DEF_INIT	 RKP_CMDID(1)

#define RKP_INIT_MAGIC 0x5afe0001
#define RKP_VMM_BUFFER 0x600000
#define RKP_RO_BUFFER  UL(0x800000)

/*** TODO: We need to export this so it is hard coded 
     at one place*/

#define RKP_PGT_BITMAP_LEN 0x20000

#ifdef CONFIG_SOC_EXYNOS7420

#define   TIMA_VMM_START        0x4dd00000
#define   TIMA_VMM_SIZE         1<<20

#define   TIMA_DEBUG_LOG_START  0x52300000
#define   TIMA_DEBUG_LOG_SIZE   1<<18

#define   TIMA_SEC_LOG          0x52400000
#define   TIMA_SEC_LOG_SIZE     0x7000 

#define   TIMA_PHYS_MAP         0x4da00000
#define   TIMA_PHYS_MAP_SIZE    0x300000
#define   TIMA_PHYS_MAP_OFFSET  0x200000

#define   TIMA_DASHBOARD_START  0x52407000
#define   TIMA_DASHBOARD_SIZE    0x1000

#define   TIMA_ROBUF_START      0x52408000
#define   TIMA_ROBUF_SIZE       0x7f8000 /* 8MB - RKP_SEC_LOG_SIZE - RKP_DASHBOARD_SIZE)*/

#define RKP_RBUF_VA      (phys_to_virt(TIMA_ROBUF_START))
#define RO_PAGES  0x7f8 // (TIMA_ROBUF_SIZE/PAGE_SIZE)
#define CRED_JAR_RO "cred_jar_ro"
#define TSEC_JAR	"tsec_jar"
#define VFSMNT_JAR	"vfsmnt_cache"
#endif /* CONFIG_SOC_EXYNOS7420 */

extern u8 rkp_pgt_bitmap[];
extern u8 rkp_map_bitmap[];

typedef struct rkp_init rkp_init_t;
extern u8 rkp_started;
extern void *rkp_ro_alloc(void);
extern void rkp_ro_free(void *free_addr);
#ifdef CONFIG_KNOX_KAP
extern int boot_mode_security;
#endif  //CONFIG_KNOX_KAP
extern int rkp_support_large_memory;

struct rkp_init {
	u32 magic;
	u64 vmalloc_start;
	u64 vmalloc_end;
	u64 init_mm_pgd;
	u64 id_map_pgd;
	u64 zero_pg_addr;
	u64 rkp_pgt_bitmap;
	u64 rkp_map_bitmap;
	u32 rkp_pgt_bitmap_size;
	u64 _text;
	u64 _etext;
	u64 extra_memory_addr;
	u32 extra_memory_size;
	u64 physmap_addr;
	u64 _srodata;
	u64 _erodata;
	u32 large_memory;
} __attribute__((packed));

#ifdef CONFIG_RKP_KDP
typedef struct kdp_init
{
	u32 credSize;
	u32 cred_task;
	u32 mm_task;
	u32 uid_cred;
	u32 euid_cred;
	u32 gid_cred;
	u32 egid_cred;
	u32 bp_pgd_cred;
	u32 bp_task_cred;
	u32 type_cred;
	u32 security_cred;
	u32 pid_task;
	u32 rp_task;
	u32 comm_task;
	u32 pgd_mm;
	u32 usage_cred;
	u32 task_threadinfo;
	u32 sp_size;
	u32 bp_cred_secptr;
} kdp_init_t;
#endif  /* CONFIG_RKP_KDP */

void rkp_call(unsigned long long cmd, unsigned long long arg0, unsigned long long arg1, unsigned long long arg2, unsigned long long arg3, unsigned long long arg4);

static inline u8 rkp_is_pg_protected(u64 va)
{
	u64 paddr = __pa(va) - PHYS_OFFSET;
	u64 index = (paddr>>PAGE_SHIFT);
	u64 *p = (u64 *)rkp_pgt_bitmap;
	u64 tmp = (index>>6);
	u64 rindex;
	u8 val;
	
	p += (tmp);
	rindex = index % 64;
	val = (((*p) & (1ULL<<rindex))?1:0);
	return val;
}

#define	PHYS_OFFSET_MAX		(0x140000ULL << PAGE_SHIFT)
static inline u8 rkp_is_pg_dbl_mapped(u64 pa)
{
	long long phys_addr = pa&(0xFFFFFFFFFF);
	u64 paddr = (u64)phys_addr - PHYS_OFFSET;
	u64 index = (paddr>>PAGE_SHIFT);
	u64 *p = (u64 *)rkp_map_bitmap;
	u64 tmp = (index>>6);
	u64 rindex;
	u8 val;
	
	if(phys_addr < PHYS_OFFSET || 
		(paddr > PHYS_OFFSET_MAX)) {
		return 0;	
	}
	p += (tmp);
	rindex = index % 64;
	val = (((*p) & (1ULL<<rindex))?1:0);
	return val;
}

#endif //__ASSEMBLY__

#endif //_RKP_ENTRY_H