00001 #include <malloc_align.h>
00002 #include <string.h>
00003
00004 #include <moc.h>
00005 #include <ppu/moc_dma_ppu.h>
00006 #include <internal/ppu/imoc_macros_ppu.h>
00007 #include <internal/ppu/imoc_dma_ppu.h>
00008 #include <internal/ppu/imoc_core_ppu.h>
00009
00010 int IMOC_iget_data(void* target, uint64_t source, uint32_t size, uint32_t dest,
00011 imoc_dma_request* request)
00012 {
00013 uint32_t remainder_16b;
00014 uint32_t remainder_16kb;
00015 uint32_t offset;
00016 int err;
00017 int tag_id;
00018
00019 if ((tag_id = moc_tag_reserve(dest - moc_ppu_thread_count)) < 0)
00020 {
00021 return MOC_ERR_INTERN;
00022 }
00023
00024
00025 remainder_16b = size % 16;
00026
00027 request->remainder = 0;
00028 request->size = size;
00029 request->target = target;
00030 request->dest = dest;
00031 request->tag_id = tag_id;
00032
00033
00034
00035 size -= remainder_16b;
00036
00037 offset = 0;
00038
00039
00040
00041 if (size <= MAX_DMA_CALL_SIZE)
00042 {
00043 err = spe_mfcio_put(
00044 moc_spu_thread_list[dest - moc_ppu_thread_count].speid, source,
00045 target, size, tag_id, 0, 0);
00046
00047 if (err)
00048 return MOC_ERR_INTERN;
00049 }
00050
00051
00052 else
00053 {
00054 remainder_16kb = size % MAX_DMA_CALL_SIZE;
00055 while (offset + MAX_DMA_CALL_SIZE <= size)
00056 {
00057 err = spe_mfcio_put(
00058 moc_spu_thread_list[dest - moc_ppu_thread_count].speid,
00059 source + offset, target + offset, MAX_DMA_CALL_SIZE,
00060 tag_id, 0, 0);
00061
00062 if (err)
00063 return MOC_ERR_INTERN;
00064
00065 offset += MAX_DMA_CALL_SIZE;
00066 }
00067
00068 if (remainder_16kb > 0)
00069 {
00070 err = spe_mfcio_put(
00071 moc_spu_thread_list[dest - moc_ppu_thread_count].speid,
00072 source + offset, target + offset, remainder_16kb, tag_id,
00073 0, 0);
00074
00075 if (err)
00076 return MOC_ERR_INTERN;
00077 }
00078 }
00079
00080
00081 if (remainder_16b > 0)
00082 {
00083 request->buffer = (char*) _malloc_align(16 * sizeof(char), 4);
00084
00085 err = spe_mfcio_put(
00086 moc_spu_thread_list[dest - moc_ppu_thread_count].speid, source
00087 + size, request->buffer, 16, tag_id, 0, 0);
00088
00089 if (err)
00090 return MOC_ERR_INTERN;
00091 }
00092
00093 return MOC_SUCCESS;
00094
00095 }
00096