Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/mem/smmu.h
3694 views
1
/*
2
* Copyright (c) 2018 naehrwert
3
* Copyright (c) 2018-2024 CTCaer
4
*
5
* This program is free software; you can redistribute it and/or modify it
6
* under the terms and conditions of the GNU General Public License,
7
* version 2, as published by the Free Software Foundation.
8
*
9
* This program is distributed in the hope it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#ifndef _SMMU_H_
19
#define _SMMU_H_
20
21
#include <utils/types.h>
22
#include <assert.h>
23
24
#define MC_SMMU_AVPC_ASID 0x23C
25
#define MC_SMMU_TSEC_ASID 0x294
26
27
#define SMMU_NS BIT(0)
28
#define SMMU_WRITE BIT(1)
29
#define SMMU_READ BIT(2)
30
#define SMMU_ATTR_ALL (SMMU_READ | SMMU_WRITE | SMMU_NS)
31
32
typedef struct _pde_t {
33
union {
34
union {
35
struct {
36
u32 table:22;
37
u32 rsvd:6;
38
u32 next:1;
39
u32 attr:3;
40
} tbl;
41
42
struct {
43
u32 rsvd_:10;
44
u32 page:12;
45
u32 rsvd:6;
46
u32 next:1;
47
u32 attr:3;
48
} huge;
49
};
50
51
u32 pde;
52
};
53
} pde_t;
54
55
typedef struct _pte_t {
56
u32 page:22;
57
u32 rsvd:7;
58
u32 attr:3;
59
} pte_t;
60
61
static_assert(sizeof(pde_t) == sizeof(u32), "pde_t size is wrong!");
62
static_assert(sizeof(pte_t) == sizeof(u32), "pte_t size is wrong!");
63
64
void *smmu_page_zalloc(u32 num);
65
void smmu_flush_all();
66
void smmu_init();
67
void smmu_enable();
68
void smmu_disable();
69
void smmu_reset_heap();
70
void *smmu_domain_init(u32 dev_base, u32 asid);
71
void smmu_domain_deinit(u32 dev_base, u32 asid);
72
void smmu_domain_bypass(u32 dev_base, bool bypass);
73
void smmu_map(void *ptb, u32 iova, u64 iopa, u32 pages, u32 attr);
74
void smmu_map_huge(void *ptb, u32 iova, u64 iopa, u32 regions, u32 attr);
75
76
#endif
77
78