-
Notifications
You must be signed in to change notification settings - Fork 1
/
pxa255_DMA.c
116 lines (91 loc) · 2.52 KB
/
pxa255_DMA.c
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
#include "pxa255_DMA.h"
#include "mem.h"
#define REG_DAR 0
#define REG_SAR 1
#define REG_TAR 2
#define REG_CR 3
#define REG_CSR 4
static void pxa255dmaPrvChannelRegWrite(_UNUSED_ Pxa255dma* dma, UInt8 channel, UInt8 reg, UInt32 val){
if(val){ //we start with zeros, so non-zero writes are all we care about
const char* regs[] = {"DADDR", "SADDR", "TADDR", "CR", "CSR"};
err_str("dma: writes unimpl!");
// err_str("PXA255 dma engine: writes unimpl! (writing 0x");
// err_hex(val);
// err_str(" to channel ");
// err_dec(channel);
// err_str(" reg ");
// err_str(regs[reg]);
// err_str(". Halting.\r\n");
while(1);
}
}
static UInt32 pxa255dmaPrvChannelRegRead(_UNUSED_ Pxa255dma* dma, _UNUSED_ UInt8 channel, _UNUSED_ UInt8 reg){
return 0;
}
static Boolean pxa255dmaPrvMemAccessF(void* userData, UInt32 pa, UInt8 size, Boolean write, void* buf){
Pxa255dma* dma = userData;
UInt8 reg, set;
UInt32 val = 0;
if(size != 4) {
err_str(__FILE__ ": Unexpected ");
// err_str(write ? "write" : "read");
// err_str(" of ");
// err_dec(size);
// err_str(" bytes to 0x");
// err_hex(pa);
// err_str("\r\n");
return true; //we do not support non-word accesses
}
pa = (pa - PXA255_DMA_BASE) >> 2;
if(write){
val = *(UInt32*)buf;
switch(pa >> 6){ //weird, but quick way to avoide repeated if-then-elses. this is faster
case 0:
if(pa < 16){
reg = REG_CSR;
set = pa;
pxa255dmaPrvChannelRegWrite(dma, set, reg, val);
}
break;
case 1:
pa -= 64;
if(pa < 40) dma->CMR[pa] = val;
break;
case 2:
pa -= 128;
set = pa >> 2;
reg = pa & 3;
pxa255dmaPrvChannelRegWrite(dma, set, reg, val);
break;
}
}
else{
switch(pa >> 6){ //weird, but quick way to avoide repeated if-then-elses. this is faster
case 0:
if(pa < 16){
reg = REG_CSR;
set = pa;
val = pxa255dmaPrvChannelRegRead(dma, set, reg);
}
break;
case 1:
pa -= 64;
if(pa < 40) val = dma->CMR[pa];
break;
case 2:
pa -= 128;
set = pa >> 2;
reg = pa & 3;
val = pxa255dmaPrvChannelRegRead(dma, set, reg);
break;
}
*(UInt32*)buf = val;
}
return true;
}
Boolean pxa255dmaInit(Pxa255dma* dma, ArmMem* physMem, Pxa255ic* ic){
__mem_zero(dma, sizeof(Pxa255dma));
dma->ic = ic;
dma->mem = physMem;
return memRegionAdd(physMem, PXA255_DMA_BASE, PXA255_DMA_SIZE, pxa255dmaPrvMemAccessF, dma);
}