11#include "irx_imports.h"
17IRX_ID(
"dmacman", 1, 1);
21static vu32 *dmac_channel_0_madr = (vu32 *)0xBF801080;
22static vu32 *dmac_channel_0_bcr = (vu32 *)0xBF801084;
23static vu32 *dmac_channel_0_chcr = (vu32 *)0xBF801088;
24static vu32 *dmac_channel_1_madr = (vu32 *)0xBF801090;
25static vu32 *dmac_channel_1_bcr = (vu32 *)0xBF801094;
26static vu32 *dmac_channel_1_chcr = (vu32 *)0xBF801098;
27static vu32 *dmac_channel_2_madr = (vu32 *)0xBF8010A0;
28static vu32 *dmac_channel_2_bcr = (vu32 *)0xBF8010A4;
29static vu32 *dmac_channel_2_chcr = (vu32 *)0xBF8010A8;
30static vu32 *dmac_channel_3_madr = (vu32 *)0xBF8010B0;
31static vu32 *dmac_channel_3_bcr = (vu32 *)0xBF8010B4;
32static vu32 *dmac_channel_3_chcr = (vu32 *)0xBF8010B8;
33static vu32 *dmac_channel_4_madr = (vu32 *)0xBF8010C0;
34static vu32 *dmac_channel_4_bcr = (vu32 *)0xBF8010C4;
35static vu32 *dmac_channel_4_chcr = (vu32 *)0xBF8010C8;
36static vu32 *dmac_channel_4_tadr = (vu32 *)0xBF8010CC;
37static vu32 *dmac_channel_5_madr = (vu32 *)0xBF8010D0;
38static vu32 *dmac_channel_5_bcr = (vu32 *)0xBF8010D4;
39static vu32 *dmac_channel_5_chcr = (vu32 *)0xBF8010D8;
40static vu32 *dmac_channel_6_madr = (vu32 *)0xBF8010E0;
41static vu32 *dmac_channel_6_bcr = (vu32 *)0xBF8010E4;
42static vu32 *dmac_channel_6_chcr = (vu32 *)0xBF8010E8;
43static vu32 *dmac_channel_7_madr = (vu32 *)0xBF801500;
44static vu32 *dmac_channel_7_bcr = (vu32 *)0xBF801504;
45static vu32 *dmac_channel_7_chcr = (vu32 *)0xBF801508;
46static vu32 *dmac_channel_8_madr = (vu32 *)0xBF801510;
47static vu32 *dmac_channel_8_bcr = (vu32 *)0xBF801514;
48static vu32 *dmac_channel_8_chcr = (vu32 *)0xBF801518;
49static vu32 *dmac_channel_9_madr = (vu32 *)0xBF801520;
50static vu32 *dmac_channel_9_bcr = (vu32 *)0xBF801524;
51static vu32 *dmac_channel_9_chcr = (vu32 *)0xBF801528;
52static vu32 *dmac_channel_9_tadr = (vu32 *)0xBF80152C;
53static vu32 *dmac_channel_A_madr = (vu32 *)0xBF801530;
54static vu32 *dmac_channel_A_bcr = (vu32 *)0xBF801534;
55static vu32 *dmac_channel_A_chcr = (vu32 *)0xBF801538;
56static vu32 *dmac_channel_B_madr = (vu32 *)0xBF801540;
57static vu32 *dmac_channel_B_bcr = (vu32 *)0xBF801544;
58static vu32 *dmac_channel_B_chcr = (vu32 *)0xBF801548;
59static vu32 *dmac_channel_C_madr = (vu32 *)0xBF801550;
60static vu32 *dmac_channel_C_bcr = (vu32 *)0xBF801554;
61static vu32 *dmac_channel_C_chcr = (vu32 *)0xBF801558;
62static vu32 *dmac_channel_9_4_9_a = (vu32 *)0xBF801560;
63static vu32 *dmac_channel_A_4_9_a = (vu32 *)0xBF801564;
64static vu32 *dmac_channel_4_4_9_a = (vu32 *)0xBF801568;
65static vu32 *dmac_dpcr = (vu32 *)0xBF8010F0;
66static vu32 *dmac_dpcr2 = (vu32 *)0xBF801570;
67static vu32 *dmac_dpcr3 = (vu32 *)0xBF8015F0;
68static vu32 *dmac_dicr = (vu32 *)0xBF8010F4;
69static vu32 *dmac_dicr2 = (vu32 *)0xBF801574;
70static vu32 *dmac_BF80157C = (vu32 *)0xBF80157C;
71static vu32 *dmac_BF801578 = (vu32 *)0xBF801578;
73void dmac_ch_set_madr(u32 channel, u32 val)
77 *dmac_channel_0_madr = val;
79 case IOP_DMAC_MDECout:
80 *dmac_channel_1_madr = val;
83 *dmac_channel_2_madr = val;
86 *dmac_channel_3_madr = val;
89 *dmac_channel_4_madr = val;
92 *dmac_channel_5_madr = val;
95 *dmac_channel_6_madr = val;
98 *dmac_channel_7_madr = val;
101 *dmac_channel_8_madr = val;
104 *dmac_channel_9_madr = val;
107 *dmac_channel_A_madr = val;
109 case IOP_DMAC_SIO2in:
110 *dmac_channel_B_madr = val;
112 case IOP_DMAC_SIO2out:
113 *dmac_channel_C_madr = val;
120u32 dmac_ch_get_madr(u32 channel)
123 case IOP_DMAC_MDECin:
124 return *dmac_channel_0_madr;
125 case IOP_DMAC_MDECout:
126 return *dmac_channel_1_madr;
128 return *dmac_channel_2_madr;
130 return *dmac_channel_3_madr;
132 return *dmac_channel_4_madr;
134 return *dmac_channel_5_madr;
136 return *dmac_channel_6_madr;
138 return *dmac_channel_7_madr;
140 return *dmac_channel_8_madr;
142 return *dmac_channel_9_madr;
144 return *dmac_channel_A_madr;
145 case IOP_DMAC_SIO2in:
146 return *dmac_channel_B_madr;
147 case IOP_DMAC_SIO2out:
148 return *dmac_channel_C_madr;
154void dmac_ch_set_bcr(u32 channel, u32 val)
157 case IOP_DMAC_MDECin:
158 *dmac_channel_0_bcr = val;
160 case IOP_DMAC_MDECout:
161 *dmac_channel_1_bcr = val;
164 *dmac_channel_2_bcr = val;
167 *dmac_channel_3_bcr = val;
170 *dmac_channel_4_bcr = val;
173 *dmac_channel_5_bcr = val;
176 *dmac_channel_6_bcr = val;
179 *dmac_channel_7_bcr = val;
182 *dmac_channel_8_bcr = val;
185 *dmac_channel_9_bcr = val;
188 *dmac_channel_A_bcr = val;
190 case IOP_DMAC_SIO2in:
191 *dmac_channel_B_bcr = val;
193 case IOP_DMAC_SIO2out:
194 *dmac_channel_C_bcr = val;
201u32 dmac_ch_get_bcr(u32 channel)
204 case IOP_DMAC_MDECin:
205 return *dmac_channel_0_bcr;
206 case IOP_DMAC_MDECout:
207 return *dmac_channel_1_bcr;
209 return *dmac_channel_2_bcr;
211 return *dmac_channel_3_bcr;
213 return *dmac_channel_4_bcr;
215 return *dmac_channel_5_bcr;
217 return *dmac_channel_6_bcr;
219 return *dmac_channel_7_bcr;
221 return *dmac_channel_8_bcr;
223 return *dmac_channel_9_bcr;
225 return *dmac_channel_A_bcr;
226 case IOP_DMAC_SIO2in:
227 return *dmac_channel_B_bcr;
228 case IOP_DMAC_SIO2out:
229 return *dmac_channel_C_bcr;
235void dmac_ch_set_chcr(u32 channel, u32 val)
238 case IOP_DMAC_MDECin:
239 *dmac_channel_0_chcr = val;
241 case IOP_DMAC_MDECout:
242 *dmac_channel_1_chcr = val;
245 *dmac_channel_2_chcr = val;
248 *dmac_channel_3_chcr = val;
251 *dmac_channel_4_chcr = val;
254 *dmac_channel_5_chcr = val;
257 *dmac_channel_6_chcr = val;
260 *dmac_channel_7_chcr = val;
263 *dmac_channel_8_chcr = val;
266 *dmac_channel_9_chcr = val;
269 *dmac_channel_A_chcr = val;
271 case IOP_DMAC_SIO2in:
272 *dmac_channel_B_chcr = val;
274 case IOP_DMAC_SIO2out:
275 *dmac_channel_C_chcr = val;
282u32 dmac_ch_get_chcr(u32 channel)
285 case IOP_DMAC_MDECin:
286 return *dmac_channel_0_chcr;
287 case IOP_DMAC_MDECout:
288 return *dmac_channel_1_chcr;
290 return *dmac_channel_2_chcr;
292 return *dmac_channel_3_chcr;
294 return *dmac_channel_4_chcr;
296 return *dmac_channel_5_chcr;
298 return *dmac_channel_6_chcr;
300 return *dmac_channel_7_chcr;
302 return *dmac_channel_8_chcr;
304 return *dmac_channel_9_chcr;
306 return *dmac_channel_A_chcr;
307 case IOP_DMAC_SIO2in:
308 return *dmac_channel_B_chcr;
309 case IOP_DMAC_SIO2out:
310 return *dmac_channel_C_chcr;
316void dmac_ch_set_tadr(u32 channel, u32 val)
320 *dmac_channel_4_tadr = val;
323 *dmac_channel_9_tadr = val;
330u32 dmac_ch_get_tadr(u32 channel)
334 return *dmac_channel_4_tadr;
336 return *dmac_channel_9_tadr;
342void dmac_set_4_9_a(u32 channel, u32 val)
346 *dmac_channel_4_4_9_a = val;
349 *dmac_channel_9_4_9_a = val;
352 *dmac_channel_A_4_9_a = val;
359u32 dmac_get_4_9_a(u32 channel)
363 return *dmac_channel_4_4_9_a;
365 return *dmac_channel_9_4_9_a;
367 return *dmac_channel_A_4_9_a;
373void dmac_set_dpcr(u32 val)
378u32 dmac_get_dpcr(
void)
383void dmac_set_dpcr2(u32 val)
388u32 dmac_get_dpcr2(
void)
393void dmac_set_dpcr3(u32 val)
398u32 dmac_get_dpcr3(
void)
403void dmac_set_dicr(u32 val)
408u32 dmac_get_dicr(
void)
413void dmac_set_dicr2(u32 val)
418u32 dmac_get_dicr2(
void)
423void dmac_set_BF80157C(u32 val)
425 *dmac_BF80157C = val;
428u32 dmac_get_BF80157C(
void)
430 return *dmac_BF80157C;
433void dmac_set_BF801578(u32 val)
435 *dmac_BF801578 = val;
438u32 dmac_get_BF801578(
void)
440 return *dmac_BF801578;
443int _start(
int argc,
char *argv[])
450 if (RegisterLibraryEntries(&_exp_dmacman) != 0) {
454 dmac_set_dpcr(0x7777777);
455 dmac_set_dpcr2(0x7777777);
456 dmac_set_dpcr3(0x777);
459 for (i = 0; i < 0xD; i += 1) {
460 dmac_ch_set_madr(i, 0);
461 dmac_ch_set_bcr(i, 0);
462 dmac_ch_set_chcr(i, 0);
466 dmac_ch_set_tadr(IOP_DMAC_SPU, 0);
467 dmac_ch_set_tadr(IOP_DMAC_SIF0, 0);
468 dmac_set_4_9_a(IOP_DMAC_SPU, 0);
469 dmac_set_4_9_a(IOP_DMAC_SIF0, 0);
470 dmac_set_4_9_a(IOP_DMAC_SIF1, 0);
471 dmac_set_BF801578(1);
481 dmac_set_BF801578(0);
484 for (i = 0; i < 0xD; i += 1) {
487 value = dmac_ch_get_chcr(i);
488 if ((value & 0x1000000) != 0) {
489 Kprintf(
"WARNING:DMA %dch has been continued until shutdown\n", i);
491 dmac_ch_set_chcr(i, value & (~0x1000000));
499int sceSetSliceDMA(u32 channel,
void *addr, u32 size, u32
count,
int dir)
501 if (channel >= 0xD || channel == IOP_DMAC_OTC) {
504 dmac_ch_set_madr(channel, (
unsigned int)addr & 0xFFFFFF);
505 dmac_ch_set_bcr(channel, (size & 0xFFFF) | (
count << 16));
506 dmac_ch_set_chcr(channel, (dir & 1) | 0x200 | ((dir == 0) ? 0x40000000 : 0));
510int dmac_set_dma_chained_spu_sif0(u32 channel, u32 size, u32 tadr)
512 if (channel == IOP_DMAC_SPU || channel == IOP_DMAC_SIF0) {
513 dmac_ch_set_bcr(channel, size & 0xFFFF);
514 dmac_ch_set_chcr(channel, 0x601);
515 dmac_ch_set_tadr(channel, tadr & 0xFFFFFF);
521int dmac_set_dma_sif0(u32 channel, u32 size, u32 tadr)
523 if (channel != IOP_DMAC_SIF0) {
526 dmac_ch_set_bcr(IOP_DMAC_SIF0, size & 0xFFFF);
527 dmac_ch_set_chcr(IOP_DMAC_SIF0, 0x701);
528 dmac_ch_set_tadr(IOP_DMAC_SIF0, tadr & 0xFFFFFF);
532int dmac_set_dma_sif1(u32 ch, u32 size)
534 if (ch != IOP_DMAC_SIF1) {
537 dmac_ch_set_bcr(IOP_DMAC_SIF1, size & 0xFFFF);
538 dmac_ch_set_chcr(IOP_DMAC_SIF1, 0x40000300);
542void sceStartDMA(u32 channel)
545 dmac_ch_set_chcr(channel, dmac_ch_get_chcr(channel) | 0x1000000);
549void sceSetDMAPriority(u32 channel, u32 val)
555 case IOP_DMAC_MDECin:
556 dmac_set_dpcr((dmac_get_dpcr() & (~0x7)) | (val & 7));
558 case IOP_DMAC_MDECout:
559 dmac_set_dpcr((dmac_get_dpcr() & (~0x70)) | ((val & 7) << 4));
562 dmac_set_dpcr((dmac_get_dpcr() & (~0x700)) | ((val & 7) << 8));
565 dmac_set_dpcr((dmac_get_dpcr() & (~0x7000)) | ((val & 7) << 12));
568 dmac_set_dpcr((dmac_get_dpcr() & (~0x70000)) | ((val & 7) << 16));
571 dmac_set_dpcr((dmac_get_dpcr() & (~0x700000)) | ((val & 7) << 20));
574 dmac_set_dpcr((dmac_get_dpcr() & (~0x7000000)) | ((val & 7) << 24));
577 dmac_set_dpcr2((dmac_get_dpcr2() & (~0x7)) | (val & 7));
580 dmac_set_dpcr2((dmac_get_dpcr2() & (~0x70)) | ((val & 7) << 4));
583 dmac_set_dpcr2((dmac_get_dpcr2() & (~0x700)) | ((val & 7) << 8));
586 dmac_set_dpcr2((dmac_get_dpcr2() & (~0x7000)) | ((val & 7) << 12));
588 case IOP_DMAC_SIO2in:
589 dmac_set_dpcr2((dmac_get_dpcr2() & (~0x70000)) | ((val & 7) << 16));
591 case IOP_DMAC_SIO2out:
592 dmac_set_dpcr2((dmac_get_dpcr2() & (~0x700000)) | ((val & 7) << 20));
595 dmac_set_dpcr3((dmac_get_dpcr3() & (~0x7)) | (val & 7));
598 dmac_set_dpcr3((dmac_get_dpcr3() & (~0x70)) | ((val & 7) << 4));
601 dmac_set_dpcr3((dmac_get_dpcr3() & (~0x700)) | ((val & 7) << 8));
604 dmac_set_dpcr((dmac_get_dpcr() & (~0x70000000)) | ((val & 7) << 28));
607 dmac_set_dpcr2((dmac_get_dpcr2() & (~0x7000000)) | ((val & 7) << 24));
615void sceEnableDMAChannel(u32 channel)
621 case IOP_DMAC_MDECin:
622 dmac_set_dpcr(dmac_get_dpcr() | 0x8);
624 case IOP_DMAC_MDECout:
625 dmac_set_dpcr(dmac_get_dpcr() | 0x80);
628 dmac_set_dpcr(dmac_get_dpcr() | 0x800);
631 dmac_set_dpcr(dmac_get_dpcr() | 0x8000);
634 dmac_set_dpcr(dmac_get_dpcr() | 0x80000);
637 dmac_set_dpcr(dmac_get_dpcr() | 0x800000);
640 dmac_set_dpcr(dmac_get_dpcr() | 0x8000000);
643 dmac_set_dpcr2(dmac_get_dpcr2() | 0x8);
646 dmac_set_dpcr2(dmac_get_dpcr2() | 0x80);
649 dmac_set_dpcr2(dmac_get_dpcr2() | 0x800);
652 dmac_set_dpcr2(dmac_get_dpcr2() | 0x8000);
654 case IOP_DMAC_SIO2in:
655 dmac_set_dpcr2(dmac_get_dpcr2() | 0x80000);
657 case IOP_DMAC_SIO2out:
658 dmac_set_dpcr2(dmac_get_dpcr2() | 0x800000);
661 dmac_set_dpcr3(dmac_get_dpcr3() | 0x8);
664 dmac_set_dpcr3(dmac_get_dpcr3() | 0x80);
667 dmac_set_dpcr3(dmac_get_dpcr3() | 0x800);
670 dmac_set_dpcr2(dmac_get_dpcr2() | 0x8000000);
678void sceDisableDMAChannel(u32 channel)
684 case IOP_DMAC_MDECin:
685 dmac_set_dpcr(dmac_get_dpcr() & (~0x8));
687 case IOP_DMAC_MDECout:
688 dmac_set_dpcr(dmac_get_dpcr() & (~0x80));
691 dmac_set_dpcr(dmac_get_dpcr() & (~0x800));
694 dmac_set_dpcr(dmac_get_dpcr() & (~0x8000));
697 dmac_set_dpcr(dmac_get_dpcr() & (~0x80000));
700 dmac_set_dpcr(dmac_get_dpcr() & (~0x800000));
703 dmac_set_dpcr(dmac_get_dpcr() & (~0x8000000));
706 dmac_set_dpcr2(dmac_get_dpcr2() & (~0x8));
709 dmac_set_dpcr2(dmac_get_dpcr2() & (~0x80));
712 dmac_set_dpcr2(dmac_get_dpcr2() & (~0x800));
715 dmac_set_dpcr2(dmac_get_dpcr2() & (~0x8000));
717 case IOP_DMAC_SIO2in:
718 dmac_set_dpcr2(dmac_get_dpcr2() & (~0x80000));
720 case IOP_DMAC_SIO2out:
721 dmac_set_dpcr2(dmac_get_dpcr2() & (~0x800000));
724 dmac_set_dpcr3(dmac_get_dpcr3() & (~0x8));
727 dmac_set_dpcr3(dmac_get_dpcr3() & (~0x80));
730 dmac_set_dpcr3(dmac_get_dpcr3() & (~0x800));
733 dmac_set_dpcr2(dmac_get_dpcr2() & (~0x8000000));
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)
u32 count
start sector of fragmented bd/file