libspe2 0.9a
|
00001 /* 00002 * libspe2 - A wrapper library to adapt the JSRE SPU usage model to SPUFS 00003 * Copyright (C) 2005 IBM Corp. 00004 * 00005 * This library is free software; you can redistribute it and/or modify it 00006 * under the terms of the GNU Lesser General Public License as published by 00007 * the Free Software Foundation; either version 2.1 of the License, 00008 * or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, but 00011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this library; if not, write to the Free Software Foundation, 00017 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00022 #ifndef _spebase_h_ 00023 #define _spebase_h_ 00024 00025 #ifdef __cplusplus 00026 extern "C" 00027 { 00028 #endif 00029 00030 #include <pthread.h> 00031 00032 #include "libspe2-types.h" 00033 00034 #define __PRINTF(fmt, args...) { fprintf(stderr,fmt , ## args); } 00035 #ifdef DEBUG 00036 #define DEBUG_PRINTF(fmt, args...) __PRINTF(fmt , ## args) 00037 #else 00038 #define DEBUG_PRINTF(fmt, args...) 00039 #endif 00040 00042 enum fd_name { 00043 FD_MBOX, 00044 FD_MBOX_STAT, 00045 FD_IBOX, 00046 FD_IBOX_NB, 00047 FD_IBOX_STAT, 00048 FD_WBOX, 00049 FD_WBOX_NB, 00050 FD_WBOX_STAT, 00051 FD_SIG1, 00052 FD_SIG2, 00053 FD_MFC, 00054 FD_MSS, 00055 NUM_MBOX_FDS 00056 }; 00057 00058 /* 00059 * "Private" structure -- do no use, if you want to achieve binary compatibility 00060 */ 00061 struct spe_context_base_priv { 00062 /* mutex to protect members which modified in lifetime of the context: 00063 spe_fds_array, entry 00064 */ 00065 pthread_mutex_t fd_lock[NUM_MBOX_FDS]; 00066 00067 /* SPE Group base directory fd */ 00068 int fd_grp_dir; 00069 00070 /* SPE SPUFS base dir fd*/ 00071 int fd_spe_dir; 00072 00073 /* SPE Program execution and environment flags */ 00074 unsigned int flags; 00075 00076 /* SPE Mailbox and Signal fds */ 00077 int spe_fds_array[NUM_MBOX_FDS]; 00078 int spe_fds_refcount[NUM_MBOX_FDS]; 00079 00080 /* event pipes for speevent library */ 00081 int ev_pipe[2]; 00082 00083 /* Base Addresses of memory mapped SPE areas */ 00084 void *psmap_mmap_base; 00085 void *mem_mmap_base; 00086 void *mfc_mmap_base; 00087 void *mssync_mmap_base; 00088 void *cntl_mmap_base; 00089 void *signal1_mmap_base; 00090 void *signal2_mmap_base; 00091 00092 /* SPE program entry point generated by elf_load() */ 00093 int entry; 00094 00095 /* pointer to the program loaded/being loaded to the SPE. We need to 00096 * store this to allow deferred updates to gdb, when loading is 00097 * asynchronous (ie, isolated load, which is performed by the SPE). 00098 */ 00099 spe_program_handle_t *loaded_program; 00100 00101 /* We need to keep the entry point for emulated isolated contexts, 00102 * and ignore the value provided to spe_context_run */ 00103 int emulated_entry; 00104 00105 /* This is used to keep track of tags used for proxy DMA operations 00106 * so we can use the zero tagmask parameter in the status functions*/ 00107 00108 int active_tagmask; 00109 }; 00110 00111 00112 /* spe related sizes 00113 */ 00114 00115 #define LS_SIZE 0x40000 /* 256K (in bytes) */ 00116 #define PSMAP_SIZE 0x20000 /* 128K (in bytes) */ 00117 #define MFC_SIZE 0x1000 00118 #define MSS_SIZE 0x1000 00119 #define CNTL_SIZE 0x1000 00120 #define SIGNAL_SIZE 0x1000 00121 00122 #define MSSYNC_OFFSET 0x00000 00123 #define MFC_OFFSET 0x03000 00124 #define CNTL_OFFSET 0x04000 00125 #define SIGNAL1_OFFSET 0x14000 00126 #define SIGNAL2_OFFSET 0x1c000 00127 00132 #define SPE_EMULATE_PARAM_BUFFER 0x3e000 00133 00134 /* 00135 */ 00136 #define SPE_PROGRAM_NORMAL_END 0x2000 00137 #define SPE_PROGRAM_LIBRARY_CALL 0x2100 00138 00142 #define SPE_PROGRAM_ISOLATED_STOP 0x2200 00143 #define SPE_PROGRAM_ISO_LOAD_COMPLETE 0x2206 00144 00150 struct spe_gang_context_base_priv 00151 { 00152 /* SPE Gang execution and environment flags */ 00153 unsigned int flags; 00154 00155 /* SPE Mailbox and Signal fds */ 00156 int fd_gang_dir; 00157 00158 char gangname[256]; 00159 }; 00160 00161 00162 /* Function Prototypes 00163 */ 00164 00174 extern spe_context_ptr_t _base_spe_context_create(unsigned int flags, spe_gang_context_ptr_t gctx, spe_context_ptr_t aff_spe); 00175 00185 extern spe_gang_context_ptr_t _base_spe_gang_context_create(unsigned int flags); 00186 00194 extern int _base_spe_program_load(spe_context_ptr_t spectx, spe_program_handle_t *program); 00195 00205 void _base_spe_program_load_complete(spe_context_ptr_t spectx); 00206 00211 int _base_spe_emulated_loader_present(void); 00212 00219 extern int _base_spe_context_destroy(spe_context_ptr_t spectx); 00220 00226 extern int _base_spe_gang_context_destroy(spe_gang_context_ptr_t gctx); 00227 00248 extern int _base_spe_context_run(spe_context_ptr_t spe, unsigned int *entry, 00249 unsigned int runflags, void *argp, void *envp, spe_stop_info_t *stopinfo); 00250 00262 extern int _base_spe_image_close(spe_program_handle_t *handle); 00263 00294 extern spe_program_handle_t *_base_spe_image_open(const char *filename); 00295 00313 extern int _base_spe_mfcio_put(spe_context_ptr_t spectx, 00314 unsigned int ls, 00315 void *ea, 00316 unsigned int size, 00317 unsigned int tag, 00318 unsigned int tid, 00319 unsigned int rid); 00320 00337 int _base_spe_mfcio_putb(spe_context_ptr_t spectx, 00338 unsigned int ls, 00339 void *ea, 00340 unsigned int size, 00341 unsigned int tag, 00342 unsigned int tid, 00343 unsigned int rid); 00344 00360 int _base_spe_mfcio_putf(spe_context_ptr_t spectx, 00361 unsigned int ls, 00362 void *ea, 00363 unsigned int size, 00364 unsigned int tag, 00365 unsigned int tid, 00366 unsigned int rid); 00367 00384 int _base_spe_mfcio_get(spe_context_ptr_t spectx, 00385 unsigned int ls, 00386 void *ea, 00387 unsigned int size, 00388 unsigned int tag, 00389 unsigned int tid, 00390 unsigned int rid); 00391 00408 int _base_spe_mfcio_getb(spe_context_ptr_t spectx, 00409 unsigned int ls, 00410 void *ea, 00411 unsigned int size, 00412 unsigned int tag, 00413 unsigned int tid, 00414 unsigned int rid); 00415 00431 int _base_spe_mfcio_getf(spe_context_ptr_t spectx, 00432 unsigned int ls, 00433 void *ea, 00434 unsigned int size, 00435 unsigned int tag, 00436 unsigned int tid, 00437 unsigned int rid); 00438 00461 int _base_spe_out_mbox_read(spe_context_ptr_t spectx, 00462 unsigned int mbox_data[], 00463 int count); 00464 00493 int _base_spe_in_mbox_write(spe_context_ptr_t spectx, 00494 unsigned int mbox_data[], 00495 int count, 00496 int behavior_flag); 00497 00509 int _base_spe_in_mbox_status(spe_context_ptr_t spectx); 00510 00522 int _base_spe_out_mbox_status(spe_context_ptr_t spectx); 00523 00535 int _base_spe_out_intr_mbox_status(spe_context_ptr_t spectx); 00536 00541 int _base_spe_out_intr_mbox_read(spe_context_ptr_t spectx, 00542 unsigned int mbox_data[], 00543 int count, 00544 int behavior_flag); 00545 00560 int _base_spe_signal_write(spe_context_ptr_t spectx, 00561 unsigned int signal_reg, 00562 unsigned int data ); 00563 00568 extern int _base_spe_callback_handler_register(void * handler, unsigned int callnum, unsigned int mode); 00569 00574 extern int _base_spe_callback_handler_deregister(unsigned int callnum ); 00575 00579 extern void * _base_spe_callback_handler_query(unsigned int callnum ); 00580 00594 int _base_spe_stop_reason_get(spe_context_ptr_t spectx); 00595 00596 00602 int _base_spe_mfcio_tag_status_read(spe_context_ptr_t spectx, unsigned int mask, unsigned int behavior, unsigned int *tag_status); 00603 00609 int __base_spe_stop_event_source_get(spe_context_ptr_t spectx); 00610 00616 int __base_spe_stop_event_target_get(spe_context_ptr_t spectx); 00617 00624 int _base_spe_stop_status_get(spe_context_ptr_t spectx); 00625 00633 int __base_spe_event_source_acquire(struct spe_context *spectx, enum fd_name fdesc); 00634 00642 void __base_spe_event_source_release(struct spe_context *spectx, enum fd_name fdesc); 00643 00652 void* _base_spe_ps_area_get(struct spe_context *spectx, enum ps_area area); 00653 00659 int __base_spe_spe_dir_get(struct spe_context *spectx); 00660 00667 void* _base_spe_ls_area_get(struct spe_context *spectx); 00668 00674 int _base_spe_ls_size_get(spe_context_ptr_t spe); 00675 00682 void _base_spe_context_lock(spe_context_ptr_t spe, enum fd_name fd); 00683 00690 void _base_spe_context_unlock(spe_context_ptr_t spe, enum fd_name fd); 00691 00695 int _base_spe_cpu_info_get(int info_requested, int cpu_node); 00696 00701 void __spe_context_update_event(void); 00702 00708 int _base_spe_mssync_start(spe_context_ptr_t spectx); 00709 00715 int _base_spe_mssync_status(spe_context_ptr_t spectx); 00716 00717 00718 #ifdef __cplusplus 00719 } 00720 #endif 00721 00722 #endif