libspe2  0.9a
Functions
mbox.c File Reference
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <stdio.h>
#include <unistd.h>
#include "create.h"
#include "mbox.h"
Include dependency graph for mbox.c:

Go to the source code of this file.

Functions

int _base_spe_out_mbox_read (spe_context_ptr_t spectx, unsigned int mbox_data[], int count)
 
int _base_spe_in_mbox_write (spe_context_ptr_t spectx, unsigned int *mbox_data, int count, int behavior_flag)
 
int _base_spe_in_mbox_status (spe_context_ptr_t spectx)
 
int _base_spe_out_mbox_status (spe_context_ptr_t spectx)
 
int _base_spe_out_intr_mbox_status (spe_context_ptr_t spectx)
 
int _base_spe_out_intr_mbox_read (spe_context_ptr_t spectx, unsigned int mbox_data[], int count, int behavior_flag)
 
int _base_spe_signal_write (spe_context_ptr_t spectx, unsigned int signal_reg, unsigned int data)
 

Function Documentation

int _base_spe_in_mbox_status ( spe_context_ptr_t  spectx)

The _base_spe_in_mbox_status function fetches the status of the SPU inbound mailbox for the SPE thread specified by the speid parameter. A 0 value is return if the mailbox is full. A non-zero value specifies the number of available (32-bit) mailbox entries.

Parameters
spectxSpecifies the SPE context whose mailbox status is to be read.
Returns
On success, returns the current status of the mailbox, respectively. On failure, -1 is returned.
See Also
spe_read_out_mbox, spe_write_in_mbox, read (2)

Definition at line 202 of file mbox.c.

References _base_spe_open_if_closed(), spe_context::base_private, spe_context_base_priv::cntl_mmap_base, FD_WBOX_STAT, spe_context_base_priv::flags, SPE_MAP_PS, and spe_spu_control_area::SPU_Mbox_Stat.

203 {
204  int rc, ret;
205  volatile struct spe_spu_control_area *cntl_area =
206  spectx->base_private->cntl_mmap_base;
207 
208  if (spectx->base_private->flags & SPE_MAP_PS) {
209  ret = (cntl_area->SPU_Mbox_Stat >> 8) & 0xFF;
210  } else {
211  rc = read(_base_spe_open_if_closed(spectx,FD_WBOX_STAT, 0), &ret, 4);
212  if (rc != 4)
213  ret = -1;
214  }
215 
216  return ret;
217 
218 }
unsigned int SPU_Mbox_Stat
Definition: cbea_map.h:60
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
void * cntl_mmap_base
Definition: spebase.h:88
#define SPE_MAP_PS
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
unsigned int flags
Definition: spebase.h:74

Here is the call graph for this function:

int _base_spe_in_mbox_write ( spe_context_ptr_t  spectx,
unsigned int *  mbox_data,
int  count,
int  behavior_flag 
)

Definition at line 112 of file mbox.c.

References _base_spe_open_if_closed(), spe_context::base_private, FD_WBOX, FD_WBOX_NB, spe_context_base_priv::flags, SPE_MAP_PS, SPE_MBOX_ALL_BLOCKING, SPE_MBOX_ANY_BLOCKING, and SPE_MBOX_ANY_NONBLOCKING.

116 {
117  int rc;
118  int total;
119  unsigned int *aux;
120  struct pollfd fds;
121 
122  if (mbox_data == NULL || count < 1){
123  errno = EINVAL;
124  return -1;
125  }
126 
127  switch (behavior_flag) {
128  case SPE_MBOX_ALL_BLOCKING: // write all, even if blocking
129  total = rc = 0;
130  if (spectx->base_private->flags & SPE_MAP_PS) {
131  do {
132  aux = mbox_data + total;
133  total += _base_spe_in_mbox_write_ps(spectx, aux, count - total);
134  if (total < count) { // we could not write everything, wait for space
135  fds.fd = _base_spe_open_if_closed(spectx, FD_WBOX, 0);
136  fds.events = POLLOUT;
137  rc = poll(&fds, 1, -1);
138  if (rc == -1 )
139  return -1;
140  }
141  } while (total < count);
142  } else {
143  while (total < 4*count) {
144  rc = write(_base_spe_open_if_closed(spectx,FD_WBOX, 0),
145  (const char *)mbox_data + total, 4*count - total);
146  if (rc == -1) {
147  break;
148  }
149  total += rc;
150  }
151  total /=4;
152  }
153  break;
154 
155  case SPE_MBOX_ANY_BLOCKING: // write at least one, even if blocking
156  total = rc = 0;
157  if (spectx->base_private->flags & SPE_MAP_PS) {
158  do {
159  total = _base_spe_in_mbox_write_ps(spectx, mbox_data, count);
160  if (total == 0) { // we could not anything, wait for space
161  fds.fd = _base_spe_open_if_closed(spectx, FD_WBOX, 0);
162  fds.events = POLLOUT;
163  rc = poll(&fds, 1, -1);
164  if (rc == -1 )
165  return -1;
166  }
167  } while (total == 0);
168  } else {
169  rc = write(_base_spe_open_if_closed(spectx,FD_WBOX, 0), mbox_data, 4*count);
170  total = rc/4;
171  }
172  break;
173 
174  case SPE_MBOX_ANY_NONBLOCKING: // only write, if non blocking
175  total = rc = 0;
176  // write directly if we map the PS else write via spufs
177  if (spectx->base_private->flags & SPE_MAP_PS) {
178  total = _base_spe_in_mbox_write_ps(spectx, mbox_data, count);
179  } else {
180  rc = write(_base_spe_open_if_closed(spectx,FD_WBOX_NB, 0), mbox_data, 4*count);
181  if (rc == -1 && errno == EAGAIN) {
182  rc = 0;
183  errno = 0;
184  }
185  total = rc/4;
186  }
187  break;
188 
189  default:
190  errno = EINVAL;
191  return -1;
192  }
193 
194  if (rc == -1) {
195  errno = EIO;
196  return -1;
197  }
198 
199  return total;
200 }
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
#define SPE_MBOX_ANY_NONBLOCKING
#define SPE_MBOX_ALL_BLOCKING
#define SPE_MAP_PS
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
#define SPE_MBOX_ANY_BLOCKING
unsigned int flags
Definition: spebase.h:74

Here is the call graph for this function:

int _base_spe_out_intr_mbox_read ( spe_context_ptr_t  spectx,
unsigned int  mbox_data[],
int  count,
int  behavior_flag 
)

The _base_spe_out_intr_mbox_read function reads the contents of the SPE outbound interrupting mailbox for the SPE context.

Definition at line 255 of file mbox.c.

References _base_spe_open_if_closed(), FD_IBOX, FD_IBOX_NB, SPE_MBOX_ALL_BLOCKING, SPE_MBOX_ANY_BLOCKING, and SPE_MBOX_ANY_NONBLOCKING.

259 {
260  int rc;
261  int total;
262 
263  if (mbox_data == NULL || count < 1){
264  errno = EINVAL;
265  return -1;
266  }
267 
268  switch (behavior_flag) {
269  case SPE_MBOX_ALL_BLOCKING: // read all, even if blocking
270  total = rc = 0;
271  while (total < 4*count) {
272  rc = read(_base_spe_open_if_closed(spectx,FD_IBOX, 0),
273  (char *)mbox_data + total, 4*count - total);
274  if (rc == -1) {
275  break;
276  }
277  total += rc;
278  }
279  break;
280 
281  case SPE_MBOX_ANY_BLOCKING: // read at least one, even if blocking
282  total = rc = read(_base_spe_open_if_closed(spectx,FD_IBOX, 0), mbox_data, 4*count);
283  break;
284 
285  case SPE_MBOX_ANY_NONBLOCKING: // only reaad, if non blocking
286  rc = read(_base_spe_open_if_closed(spectx,FD_IBOX_NB, 0), mbox_data, 4*count);
287  if (rc == -1 && errno == EAGAIN) {
288  rc = 0;
289  errno = 0;
290  }
291  total = rc;
292  break;
293 
294  default:
295  errno = EINVAL;
296  return -1;
297  }
298 
299  if (rc == -1) {
300  errno = EIO;
301  return -1;
302  }
303 
304  return rc / 4;
305 }
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
#define SPE_MBOX_ANY_NONBLOCKING
#define SPE_MBOX_ALL_BLOCKING
#define SPE_MBOX_ANY_BLOCKING

Here is the call graph for this function:

int _base_spe_out_intr_mbox_status ( spe_context_ptr_t  spectx)

The _base_spe_out_intr_mbox_status function fetches the status of the SPU outbound interrupt mailbox for the SPE thread specified by the speid parameter. A 0 value is return if the mailbox is empty. A non-zero value specifies the number of 32-bit unread mailbox entries.

Parameters
spectxSpecifies the SPE context whose mailbox status is to be read.
Returns
On success, returns the current status of the mailbox, respectively. On failure, -1 is returned.
See Also
spe_read_out_mbox, spe_write_in_mbox, read (2)

Definition at line 238 of file mbox.c.

References _base_spe_open_if_closed(), spe_context::base_private, spe_context_base_priv::cntl_mmap_base, FD_IBOX_STAT, spe_context_base_priv::flags, SPE_MAP_PS, and spe_spu_control_area::SPU_Mbox_Stat.

239 {
240  int rc, ret;
241  volatile struct spe_spu_control_area *cntl_area =
242  spectx->base_private->cntl_mmap_base;
243 
244  if (spectx->base_private->flags & SPE_MAP_PS) {
245  ret = (cntl_area->SPU_Mbox_Stat >> 16) & 0xFF;
246  } else {
247  rc = read(_base_spe_open_if_closed(spectx,FD_IBOX_STAT, 0), &ret, 4);
248  if (rc != 4)
249  ret = -1;
250 
251  }
252  return ret;
253 }
unsigned int SPU_Mbox_Stat
Definition: cbea_map.h:60
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
void * cntl_mmap_base
Definition: spebase.h:88
#define SPE_MAP_PS
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
unsigned int flags
Definition: spebase.h:74

Here is the call graph for this function:

int _base_spe_out_mbox_read ( spe_context_ptr_t  spectx,
unsigned int  mbox_data[],
int  count 
)

The _base_spe_out_mbox_read function reads the contents of the SPE outbound interrupting mailbox for the SPE thread speid.

The call will not block until the read request is satisfied, but instead return up to count currently available mailbox entries.

spe_stat_out_intr_mbox can be called to ensure that data is available prior to reading the outbound interrupting mailbox.

Parameters
spectxSpecifies the SPE thread whose outbound mailbox is to be read.
mbox_data
count
Return values
>0the number of 32-bit mailbox messages read
=0no data available
-1error condition and errno is set
Possible values for errno:
EINVAL speid is invalid
Exxxx what else do we need here??

Definition at line 58 of file mbox.c.

References _base_spe_open_if_closed(), spe_context::base_private, DEBUG_PRINTF, FD_MBOX, spe_context_base_priv::flags, and SPE_MAP_PS.

61 {
62  int rc;
63 
64  if (mbox_data == NULL || count < 1){
65  errno = EINVAL;
66  return -1;
67  }
68 
69  if (spectx->base_private->flags & SPE_MAP_PS) {
70  rc = _base_spe_out_mbox_read_ps(spectx, mbox_data, count);
71  } else {
72  rc = read(_base_spe_open_if_closed(spectx,FD_MBOX, 0), mbox_data, count*4);
73  DEBUG_PRINTF("%s read rc: %d\n", __FUNCTION__, rc);
74  if (rc != -1) {
75  rc /= 4;
76  } else {
77  if (errno == EAGAIN ) { // no data ready to be read
78  errno = 0;
79  rc = 0;
80  }
81  }
82  }
83  return rc;
84 }
#define DEBUG_PRINTF(fmt, args...)
Definition: elf_loader.c:45
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
#define SPE_MAP_PS
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
unsigned int flags
Definition: spebase.h:74

Here is the call graph for this function:

int _base_spe_out_mbox_status ( spe_context_ptr_t  spectx)

The _base_spe_out_mbox_status function fetches the status of the SPU outbound mailbox for the SPE thread specified by the speid parameter. A 0 value is return if the mailbox is empty. A non-zero value specifies the number of 32-bit unread mailbox entries.

Parameters
spectxSpecifies the SPE context whose mailbox status is to be read.
Returns
On success, returns the current status of the mailbox, respectively. On failure, -1 is returned.
See Also
spe_read_out_mbox, spe_write_in_mbox, read (2)

Definition at line 220 of file mbox.c.

References _base_spe_open_if_closed(), spe_context::base_private, spe_context_base_priv::cntl_mmap_base, FD_MBOX_STAT, spe_context_base_priv::flags, SPE_MAP_PS, and spe_spu_control_area::SPU_Mbox_Stat.

221 {
222  int rc, ret;
223  volatile struct spe_spu_control_area *cntl_area =
224  spectx->base_private->cntl_mmap_base;
225 
226  if (spectx->base_private->flags & SPE_MAP_PS) {
227  ret = cntl_area->SPU_Mbox_Stat & 0xFF;
228  } else {
229  rc = read(_base_spe_open_if_closed(spectx,FD_MBOX_STAT, 0), &ret, 4);
230  if (rc != 4)
231  ret = -1;
232  }
233 
234  return ret;
235 
236 }
unsigned int SPU_Mbox_Stat
Definition: cbea_map.h:60
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
void * cntl_mmap_base
Definition: spebase.h:88
#define SPE_MAP_PS
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
unsigned int flags
Definition: spebase.h:74

Here is the call graph for this function:

int _base_spe_signal_write ( spe_context_ptr_t  spectx,
unsigned int  signal_reg,
unsigned int  data 
)

The _base_spe_signal_write function writes data to the signal notification register specified by signal_reg for the SPE thread specified by the speid parameter.

Parameters
spectxSpecifies the SPE context whose signal register is to be written to.
signal_regSpecified the signal notification register to be written. Valid signal notification registers are:
SPE_SIG_NOTIFY_REG_1 SPE signal notification register 1
SPE_SIG_NOTIFY_REG_2 SPE signal notification register 2
dataThe 32-bit data to be written to the specified signal notification register.
Returns
On success, spe_write_signal returns 0. On failure, -1 is returned.
See Also
spe_get_ps_area, spe_write_in_mbox

Definition at line 307 of file mbox.c.

References _base_spe_close_if_open(), _base_spe_open_if_closed(), spe_context::base_private, FD_SIG1, FD_SIG2, spe_context_base_priv::flags, spe_context_base_priv::signal1_mmap_base, spe_context_base_priv::signal2_mmap_base, SPE_MAP_PS, SPE_SIG_NOTIFY_REG_1, SPE_SIG_NOTIFY_REG_2, spe_sig_notify_1_area::SPU_Sig_Notify_1, and spe_sig_notify_2_area::SPU_Sig_Notify_2.

310 {
311  int rc;
312 
313  if (spectx->base_private->flags & SPE_MAP_PS) {
314  if (signal_reg == SPE_SIG_NOTIFY_REG_1) {
316 
317  sig->SPU_Sig_Notify_1 = data;
318  } else if (signal_reg == SPE_SIG_NOTIFY_REG_2) {
320 
321  sig->SPU_Sig_Notify_2 = data;
322  } else {
323  errno = EINVAL;
324  return -1;
325  }
326  rc = 0;
327  } else {
328  if (signal_reg == SPE_SIG_NOTIFY_REG_1)
329  rc = write(_base_spe_open_if_closed(spectx,FD_SIG1, 0), &data, 4);
330  else if (signal_reg == SPE_SIG_NOTIFY_REG_2)
331  rc = write(_base_spe_open_if_closed(spectx,FD_SIG2, 0), &data, 4);
332  else {
333  errno = EINVAL;
334  return -1;
335  }
336 
337  if (rc == 4)
338  rc = 0;
339 
340  if (signal_reg == SPE_SIG_NOTIFY_REG_1)
342  else if (signal_reg == SPE_SIG_NOTIFY_REG_2)
344  }
345 
346  return rc;
347 }
void _base_spe_close_if_open(struct spe_context *spe, enum fd_name fdesc)
Definition: create.c:125
void * signal2_mmap_base
Definition: spebase.h:90
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
void * signal1_mmap_base
Definition: spebase.h:89
#define SPE_MAP_PS
unsigned int SPU_Sig_Notify_1
Definition: cbea_map.h:71
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
unsigned int flags
Definition: spebase.h:74
#define SPE_SIG_NOTIFY_REG_1
unsigned int SPU_Sig_Notify_2
Definition: cbea_map.h:76
#define SPE_SIG_NOTIFY_REG_2

Here is the call graph for this function: