dol: initial dol commit
[jump.git] / dol / src / dol / visitor / cell / lib / ppu / FastCommunication.h
1 /*
2  * Communication.h
3  *
4  *  Created on: Mar 3, 2009
5  *      Author: lschor
6  */
7
8 #ifndef FASTCOMMUNICATION_H_
9 #define FASTCOMMUNICATION_H_
10
11 // System includes
12 #include "cbe_mfc.h"
13 #include <stdint.h>
14 #include <stdio.h>
15 #include <ctype.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <new>
19 #include <sys/time.h>
20 #include <stddef.h>
21 #include <libspe2.h>
22 #include <pthread.h>
23
24 // Local includes
25 #include "lib/ppu/common_ppu.h"
26 #include "Fifo.h"
27 #include "WindowedFifo.h"
28 #include "../common.h"
29
30
31 // Include to allocate/free using for DMA transfers
32 #include "../lib/malloc_align.h"
33 #include "../lib/free_align.h"
34
35 //Cell Macros
36 #define waittag(tag_id) mfc_write_tag_mask(1<<tag_id);    mfc_read_tag_status_all();
37
38 #define MAXNOREQ 24
39
40 // A request
41 typedef struct _comRequest {
42     bool valid;           // If the request is valid
43     uint32_t status;      // Status of the request (write_request_sen, ...)
44
45     uint32_t tag_id;      // Tag ID
46     uint32_t queue;       // The queue which is used by the request
47
48     bool iswfifo;         // True if it is a WFIFO
49     Fifo* fifo;           // Pointer to the used FIFO
50     WindowedFifo* wfifo;  // Pointer to the WFIFO
51
52     uint32_t len;         // The len of the data
53     char* data;           // Point to the data which are stored
54     uint32_t offset;
55 } comRequest;
56
57 typedef struct _fifoCollection {
58     int type;               // local, in or out
59     int queue;            // Corresponding queue number
60
61     bool iswfifo;         // True if it is a WFIFO
62     WindowedFifo* wfifo;  // Pointer to the WFIFO
63     Fifo* fifo;           // Pointer to the FIFO
64 } fifoCollection;
65
66 /**
67  * The Communication Class
68  */
69 class FastCommunication {
70 public:
71     FastCommunication(int nrOfQueues, uint64_t *context_all, uint64_t *ea_base_all, int32_t * queueFromSPE, int32_t * queueOnSPE, uint64_t *);
72     virtual ~FastCommunication();
73
74     bool addFifo(int fifoNr, Fifo* fifo, int type, int queue);
75     bool addWFifo(int fifoNr, WindowedFifo* fifo, int type, int queue);
76
77     bool update();
78     bool empty();
79
80     static int const local = 0;
81     static int const in = 1;
82     static int const out = 2;
83
84     static int const comIn = 0;
85     static int const comOut = 1;
86
87     static int const read_request_sent = 0;
88     static int const read_started = 1;
89     static int const read_pending = 2;
90
91 protected:
92     void sendMessage(uint32_t message, int32_t process);
93     int testMessage(int32_t process);
94
95     comRequest* newRequest();
96     void deleteRequest(comRequest* request);
97     comRequest* getRequest(uint8_t status, uint32_t queue);
98
99     int _nrOfRequest;
100     comRequest _request[MAXNOREQ];
101     uint8_t _currentRequest;
102
103     int _nrOfQueues;
104     fifoCollection * _fifos;
105
106     uint64_t _ea_base;
107     uint64_t * _context_all;
108     int32_t * queueFromSPE;
109     int32_t * queueOnSPE;
110     uint64_t * _ea_ls_base;
111     uint64_t * _fifoTails;
112
113     // This is used to check the completion of the SPEs (See remarks in FifoCommunication.cpp)
114     uint8_t _nrSpeComplete;
115
116 };
117
118 #endif /* FASTCOMMUNICATION_H_ */