dol: initial dol commit
[jump.git] / dol / src / dol / visitor / cell / lib / ppu / FastCommunication.h
diff --git a/dol/src/dol/visitor/cell/lib/ppu/FastCommunication.h b/dol/src/dol/visitor/cell/lib/ppu/FastCommunication.h
new file mode 100644 (file)
index 0000000..8ba7731
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Communication.h
+ *
+ *  Created on: Mar 3, 2009
+ *      Author: lschor
+ */
+
+#ifndef FASTCOMMUNICATION_H_
+#define FASTCOMMUNICATION_H_
+
+// System includes
+#include "cbe_mfc.h"
+#include <stdint.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <new>
+#include <sys/time.h>
+#include <stddef.h>
+#include <libspe2.h>
+#include <pthread.h>
+
+// Local includes
+#include "lib/ppu/common_ppu.h"
+#include "Fifo.h"
+#include "WindowedFifo.h"
+#include "../common.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 24
+
+// A request
+typedef struct _comRequest {
+    bool valid;           // If the request is valid
+    uint32_t status;      // Status of the request (write_request_sen, ...)
+
+    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;
+} comRequest;
+
+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 *context_all, uint64_t *ea_base_all, int32_t * queueFromSPE, int32_t * queueOnSPE, uint64_t *);
+    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:
+    void sendMessage(uint32_t message, int32_t process);
+    int testMessage(int32_t process);
+
+    comRequest* newRequest();
+    void deleteRequest(comRequest* request);
+    comRequest* getRequest(uint8_t status, uint32_t queue);
+
+    int _nrOfRequest;
+    comRequest _request[MAXNOREQ];
+    uint8_t _currentRequest;
+
+    int _nrOfQueues;
+    fifoCollection * _fifos;
+
+    uint64_t _ea_base;
+    uint64_t * _context_all;
+    int32_t * queueFromSPE;
+    int32_t * queueOnSPE;
+    uint64_t * _ea_ls_base;
+    uint64_t * _fifoTails;
+
+    // This is used to check the completion of the SPEs (See remarks in FifoCommunication.cpp)
+    uint8_t _nrSpeComplete;
+
+};
+
+#endif /* FASTCOMMUNICATION_H_ */