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