de4a0279 |
1 | /* |
2 | * SPU processing offload to TI C64x DSP using bsp's c64_tools |
3 | * (C) GraÅžvydas "notaz" Ignotas, 2015 |
4 | * |
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of |
6 | * this software and associated documentation files (the "Software"), to deal in |
7 | * the Software without restriction, including without limitation the rights to |
8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
9 | * of the Software, and to permit persons to whom the Software is furnished to do |
10 | * so, subject to the following conditions: |
11 | * |
12 | * The above copyright notice and this permission notice shall be included in all |
13 | * copies or substantial portions of the Software. |
14 | * |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
21 | * SOFTWARE. |
22 | */ |
23 | |
24 | #define SYSCALLS_C |
25 | #include <libc64_dsp/include/inc_overlay.h> |
26 | #include <stddef.h> |
27 | |
28 | #include "spu.c" |
29 | #include "spu_c64x.h" |
30 | |
31 | /* dummy deps, some bloat but avoids ifdef hell in SPU code.. */ |
32 | static void thread_work_start(void) {} |
33 | static void thread_work_wait_sync(void) {} |
34 | static void thread_sync_caches(void) {} |
35 | struct out_driver *out_current; |
36 | void SetupSound(void) {} |
37 | |
38 | #if 0 |
39 | // no use, c64_tools does BCACHE_wbInvAll.. |
40 | static void sync_caches(void) |
41 | { |
42 | int ns_to = worker->ns_to; |
43 | |
44 | syscalls.cache_wb(spu.sRVBStart, sizeof(spu.sRVBStart[0]) * 2 * ns_to, 1); |
45 | syscalls.cache_wb(SSumLR, sizeof(SSumLR[0]) * 2 * ns_to, 1); |
46 | |
47 | syscalls.cache_wbInv(worker, sizeof(*worker), 1); |
48 | } |
49 | #endif |
50 | |
51 | static unsigned int exec(dsp_component_cmd_t cmd, |
52 | unsigned int arg1, unsigned int arg2, |
53 | unsigned int *ret1, unsigned int *ret2) |
54 | { |
55 | struct region_mem *mem = (void *)arg1; |
56 | int i; |
57 | |
58 | switch (cmd) { |
59 | case CCMD_INIT: |
60 | InitADSR(); |
61 | |
62 | spu.spuMemC = mem->spu_ram; |
63 | spu.sRVBStart = mem->RVB; |
64 | SSumLR = mem->SSumLR; |
65 | spu.SB = mem->SB; |
66 | spu.s_chan = mem->s_chan; |
67 | worker = &mem->worker; |
68 | memcpy(&spu_config, &mem->spu_config, sizeof(spu_config)); |
69 | |
70 | mem->sizeof_region_mem = sizeof(*mem); |
71 | mem->offsetof_s_chan1 = offsetof(typeof(*mem), s_chan[1]); |
72 | mem->offsetof_worker_ram = offsetof(typeof(*mem), worker.ch[1]); |
73 | // seems to be unneeded, no write-alloc? but just in case.. |
74 | syscalls.cache_wb(&mem->sizeof_region_mem, 3 * 4, 1); |
75 | break; |
76 | |
77 | case CCMD_DOIT: |
78 | do_channel_work(); |
79 | // c64_tools lib does BCACHE_wbInvAll() when it receives mailbox irq, |
80 | // so there is no benefit of syncing only what's needed. |
81 | // But call wbInvAll() anyway in case c64_tools is ever fixed.. |
82 | //sync_caches(); |
83 | syscalls.cache_wbInvAll(); |
84 | break; |
85 | |
86 | default: |
87 | syscalls.printf("bad cmd: %x\n", cmd); |
88 | break; |
89 | } |
90 | |
91 | return 0; |
92 | } |
93 | |
94 | #pragma DATA_SECTION(component_test_dsp, ".sec_com"); |
95 | dsp_component_t component_test_dsp = { |
96 | { |
97 | NULL, /* init */ |
98 | exec, |
99 | NULL, /* exec fastcall RPC */ |
100 | NULL, /* exit */ |
101 | }, |
102 | |
103 | COMPONENT_NAME, |
104 | }; |
105 | |
106 | DSP_COMPONENT_MAIN |
107 | |
108 | // vim:shiftwidth=1:expandtab |