00001 #include <stdlib.h>
00002 #include <string.h>
00003 #include <malloc_align.h>
00004 #include <free_align.h>
00005 #include <stdio.h>
00006 #include <spu_mfcio.h>
00007
00008 #include <internal/spu/imoc_core_spu.h>
00009 #include <internal/imoc.h>
00010 #include <spu/moc.h>
00011
00012 int MOC_Init(unsigned long long argp __attribute__((unused)), int length __attribute__((unused)), void* buffer __attribute__((unused)) )
00013 {
00014 char temp[24];
00015 uint32_t tag_id;
00016
00017 while (spu_stat_in_mbox() < 4)
00018 ;
00019
00020 *((uint32_t*) &temp[0]) = spu_read_in_mbox();
00021 *((uint32_t*) &temp[4]) = spu_read_in_mbox();
00022 *((uint32_t*) &temp[8]) = spu_read_in_mbox();
00023 *((uint32_t*) &temp[12]) = spu_read_in_mbox();
00024
00025 while (spu_stat_in_mbox() < 2)
00026 ;
00027
00028 *((uint32_t*) &temp[16]) = spu_read_in_mbox();
00029 *((uint32_t*) &temp[20]) = spu_read_in_mbox();
00030
00031 node_handle.rank = temp[0];
00032 node_handle.comm_size = temp[1];
00033 node_handle.queue_size = temp[2];
00034 node_handle.buffer_size = *((uint32_t*) &temp[4]);
00035 node_handle.buffer_base = *((uint64_t*) &temp[8]);
00036 node_handle.ls_base = *((uint64_t*) &temp[16]);
00037 node_handle.message_queue_base = _malloc_align(
00038 sizeof(moc_message_envelope_t) * (node_handle.comm_size - 1)
00039 * node_handle.queue_size, 4);
00040 if (node_handle.message_queue_base == 0)
00041 return MOC_ERR_NO_MEMORY;
00042 node_handle.status_array_base = _malloc_align(sizeof(moc_message_status_t)
00043 * (node_handle.comm_size - 1) * node_handle.queue_size, 4);
00044 if (node_handle.status_array_base == 0)
00045 return MOC_ERR_NO_MEMORY;
00046
00047 spu_write_out_mbox((uint32_t) node_handle.message_queue_base);
00048 spu_write_out_mbox((uint32_t) node_handle.status_array_base);
00049
00050 node_handle.moc_process_list = _malloc_align(sizeof(moc_process_t)
00051 * node_handle.comm_size, 4);
00052 if (node_handle.moc_process_list == 0)
00053 return MOC_ERR_NO_MEMORY;
00054
00055 while (spu_stat_in_mbox() < 2)
00056 ;
00057 *((uint32_t*) &temp[0]) = spu_read_in_mbox();
00058 *((uint32_t*) &temp[4]) = spu_read_in_mbox();
00059
00060 if ((tag_id = mfc_tag_reserve()) == MFC_TAG_INVALID)
00061 return MOC_ERR_INTERN;
00062 mfc_get((void*) node_handle.moc_process_list, *((uint64_t*) &temp[0]),
00063 sizeof(moc_process_t) * node_handle.comm_size, tag_id, 0, 0);
00064 mfc_write_tag_mask(1 << tag_id);
00065 mfc_read_tag_status_all();
00066 mfc_tag_release(tag_id);
00067 return 0;
00068 }
00069