ronnie
2022-10-14 1504bb53e29d3d46222c0b3ea994fc494b48e153
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
#ifndef MEM_INTERFACE_H
#define MEM_INTERFACE_H
 
#include <stddef.h>
#include <stdint.h>
 
#ifdef __cplusplus
extern "C"
{
#endif
 
struct SunxiMemOpsS
{
    int (*open)(void);
    void (*close)(void);
    int (*total_size)(void);
    void *(*palloc)(int /*size*/);
    void  (*pfree)(void* /*mem*/);
    void (*flush_cache)(void * /*mem*/, int /*size*/);
    void *(*cpu_get_phyaddr)(void * /*viraddr*/);
    void *(*cpu_get_viraddr)(void * /*phyaddr*/);
    int (*mem_set)(void * /*s*/, int /*c*/, size_t /*n*/);
    int (*mem_cpy)(void * /*dest*/, void * /*src*/, size_t /*n*/);
    int (*mem_read)(void * /*dest */, void * /*src*/, size_t /*n*/);
    int (*mem_write)(void * /*dest*/, void * /*src*/, size_t /*n*/);
    int (*setup)(void);
    int (*shutdown)(void);
    void *(*palloc_secure)(int /*size*/);
    int (*get_bufferFd)(void * /*viraddr*/);
    int mem_actual_width;
    int mem_actual_height;
};
 
static inline int SunxiMemOpen(struct SunxiMemOpsS *memops)
{
    return memops->open();
}
 
static inline void SunxiMemClose(struct SunxiMemOpsS *memops)
{
    memops->close();
}
 
static inline int SunxiMemTotalSize(struct SunxiMemOpsS *memops)
{
    return memops->total_size();
}
 
static inline void SunxiMemSetActualSize(struct SunxiMemOpsS *memops,int width,int height)
{
    memops->mem_actual_width = width;
    memops->mem_actual_height = height;
}
 
static inline void SunxiMemGetActualSize(struct SunxiMemOpsS *memops,int *width,int *height)
{
    *width = memops->mem_actual_width;
    *height = memops->mem_actual_height;
}
 
static inline void *SunxiMemPalloc(struct SunxiMemOpsS *memops,
       int nSize)
{
    return memops->palloc(nSize);
}
 
static inline void SunxiMemPfree(struct SunxiMemOpsS *memops,
       void *pMem)
{
    memops->pfree(pMem);
}
 
static inline void SunxiMemFlushCache(struct SunxiMemOpsS *memops,
       void *pMem, int nSize)
{
    memops->flush_cache(pMem, nSize);
}
 
static inline void SunxiMemSet(struct SunxiMemOpsS *memops,
       void *pMem, int nValue, int nSize)
{
   memops->mem_set(pMem, nValue, nSize);
}
 
static inline void SunxiMemCopy(struct SunxiMemOpsS *memops,
       void *pMemDst, void *pMemSrc, int nSize)
{
    memops->mem_cpy(pMemDst, pMemSrc, nSize);
}
 
static inline int SunxiMemRead(struct SunxiMemOpsS *memops,
       void *pMemDst, void *pMemSrc, int nSize)
{
    memops->mem_read(pMemDst, pMemSrc, nSize);
    return 0;
}
 
static inline int SunxiMemWrite(struct SunxiMemOpsS *memops,
       void *pMemDst, void *pMemSrc, int nSize)
{
    (void)memops; /*not use memops */
    memops->mem_write(pMemDst, pMemSrc, nSize);
    return 0;
}
 
static inline void *SunxiMemGetPhysicAddressCpu(struct SunxiMemOpsS *memops,
       void *virt)
{
    return memops->cpu_get_phyaddr(virt);
}
 
static inline void *SunxiMemGetVirtualAddressCpu(struct SunxiMemOpsS *memops,
       void *phy)
{
    return memops->cpu_get_viraddr(phy);
}
 
static inline int SunxiMemSetup(struct SunxiMemOpsS *memops)
{
    return memops->setup();
}
 
static inline int SunxiMemShutdown(struct SunxiMemOpsS *memops)
{
    return memops->shutdown();
}
 
static inline void *SunxiMemPallocSecure(struct SunxiMemOpsS *memops, int nSize)
{
    return memops->palloc_secure(nSize);
}
 
static inline int SunxiMemGetBufferFd(struct SunxiMemOpsS *memops,
       void *virt)
{
    return memops->get_bufferFd(virt);
}
 
 
struct SunxiMemOpsS* GetMemAdapterOpsS(void);
 
#ifdef __cplusplus
}
#endif
 
#endif