dol: initial dol commit
[jump.git] / dol / src / dol / visitor / cell / lib / spu / FastCommunication.h
diff --git a/dol/src/dol/visitor/cell/lib/spu/FastCommunication.h b/dol/src/dol/visitor/cell/lib/spu/FastCommunication.h
new file mode 100644 (file)
index 0000000..a787556
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * FastCommunication.h
+ *
+ *  Created on: Mar 3, 2009
+ *      Author: lschor
+ */
+
+#ifndef FASTCOMMUNICATION_H_
+#define FASTCOMMUNICATION_H_
+
+// CBE includes
+#include <spu_intrinsics.h>
+#include <spu_mfcio.h>
+
+// C++ includes
+#include <stdint.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <new>
+
+// Local includes
+#include "Fifo.h"
+#include "WindowedFifo.h"
+#include "../common.h"
+
+// For external Mailbox Communication
+#include "../spu_mfcio_ext.h"
+
+// Include to allocate/free using for DMA transfers
+#include "../lib/malloc_align.h"
+#include "../lib/free_align.h"
+
+//Cell Macros
+#define waittag(tag_id) mfc_write_tag_mask(1<<tag_id);    mfc_read_tag_status_all();
+
+#define MAXNOREQ 256
+
+// This is a full Request
+typedef struct _comRequest {
+    bool valid;              // If the request is valid
+    uint32_t status;      // Status of the request (read_..., ...)
+    
+    uint32_t tag_id;      // Tag ID
+    uint32_t queue;       // The queue which is used by the request
+    
+    bool iswfifo;         // True if it is a WFIFO
+    Fifo* fifo;           // Pointer to the used FIFO
+    WindowedFifo* wfifo;  // Pointer to the WFIFO
+
+    uint32_t len;           // The len of the data
+    char* data;           // Point to the data which are stored    
+    uint32_t offset;      // Offset generated by alignment
+} comRequest;
+
+// Struct to store a FIFO
+typedef struct _fifoCollection {
+    int type;               // local, in or out
+    int queue;            // Corresponding queue number
+
+    bool iswfifo;         // True if it is a WFIFO
+    WindowedFifo* wfifo;  // Pointer to the WFIFO
+    Fifo* fifo;           // Pointer to the FIFO   
+} fifoCollection;
+
+/**
+ * The Communication Class
+ */
+class FastCommunication {
+public:
+    FastCommunication(int nrOfQueues, uint64_t ea_base, uint64_t *ea_base_all, int32_t * queueFromSPE, int32_t * queueOnSPE, uint64_t * fifoTails);
+    virtual ~FastCommunication();
+
+    bool addFifo(int fifoNr, Fifo* fifo, int type, int queue);
+    bool addWFifo(int fifoNr, WindowedFifo* fifo, int type, int queue);
+    
+    bool update();
+    bool empty();
+
+    static int const local = 0;
+    static int const in = 1;
+    static int const out = 2;
+
+    static int const comIn = 0;
+    static int const comOut = 1;
+
+    static int const read_request_sent = 0;
+    static int const read_started = 1;
+    static int const read_pending = 2;
+
+protected:
+    // To send messages
+    void sendMessage(uint32_t message, int32_t process);
+    int testMessage(int32_t process);
+
+    // Requests
+    comRequest* newRequest();
+    void deleteRequest(comRequest* request);
+    comRequest* getRequest(uint8_t status, uint32_t queue);
+
+    // Queues
+    int _nrOfQueues;
+    fifoCollection * _fifos;
+
+    // Request
+    int _nrOfRequest;           // Need only 2 requests per queue (others are blocked...)
+    comRequest _request[MAXNOREQ];    // Stores at maximum 12 requests
+    uint8_t _currentRequest;    // The current request (so that we can start in the next iteration by the next one)
+    
+    // Pointers for communication
+    uint64_t _ea_base;          // This is my base address
+    uint64_t * _ea_base_all;    // All base addresses of the control blocks of the other SPEs (for sending message to)
+    int32_t * queueFromSPE;     // Array which tells us from which processor a queue comes
+    int32_t * queueOnSPE;       // Array which tells us to which processor a queue goes
+    uint64_t * _fifoTails;      // Pointers to the tail of the other queues
+};
+
+#endif /* FASTCOMMUNICATION_H_ */