Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/mem/smmu.h
1476 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
#include <assert.h>
19
20
#include <utils/types.h>
21
22
#define MC_SMMU_AVPC_ASID 0x23C
23
#define MC_SMMU_TSEC_ASID 0x294
24
25
#define SMMU_NS BIT(0)
26
#define SMMU_WRITE BIT(1)
27
#define SMMU_READ BIT(2)
28
#define SMMU_ATTR_ALL (SMMU_READ | SMMU_WRITE | SMMU_NS)
29
30
typedef struct _pde_t {
31
union {
32
union {
33
struct {
34
u32 table:22;
35
u32 rsvd:6;
36
u32 next:1;
37
u32 attr:3;
38
} tbl;
39
40
struct {
41
u32 rsvd_:10;
42
u32 page:12;
43
u32 rsvd:6;
44
u32 next:1;
45
u32 attr:3;
46
} huge;
47
};
48
49
u32 pde;
50
};
51
} pde_t;
52
53
typedef struct _pte_t {
54
u32 page:22;
55
u32 rsvd:7;
56
u32 attr:3;
57
} pte_t;
58
59
static_assert(sizeof(pde_t) == sizeof(u32), "pde_t size is wrong!");
60
static_assert(sizeof(pte_t) == sizeof(u32), "pte_t size is wrong!");
61
62
void *smmu_page_zalloc(u32 num);
63
void smmu_flush_all();
64
void smmu_init();
65
void smmu_enable();
66
void smmu_reset_heap();
67
void *smmu_init_domain(u32 dev_base, u32 asid);
68
void smmu_deinit_domain(u32 dev_base, u32 asid);
69
void smmu_domain_bypass(u32 dev_base, bool bypass);
70
void smmu_map(void *ptb, u32 iova, u64 iopa, u32 pages, u32 attr);
71
void smmu_map_huge(void *ptb, u32 iova, u64 iopa, u32 regions, u32 attr);
72
73