28 #include <sys/types.h>
44 [
FD_MBOX_STAT] = { .name =
"mbox_stat", .mode = O_RDONLY },
45 [
FD_IBOX] = { .name =
"ibox", .mode = O_RDONLY },
46 [
FD_IBOX_NB] = { .name =
"ibox", .mode = O_RDONLY |O_NONBLOCK },
47 [
FD_IBOX_STAT] = { .name =
"ibox_stat", .mode = O_RDONLY },
48 [
FD_WBOX] = { .name =
"wbox", .mode = O_WRONLY },
49 [
FD_WBOX_NB] = { .name =
"wbox", .mode = O_WRONLY|O_NONBLOCK },
50 [
FD_WBOX_STAT] = { .name =
"wbox_stat", .mode = O_RDONLY },
51 [
FD_SIG1] = { .name =
"signal1", .mode = O_WRONLY },
52 [
FD_SIG2] = { .name =
"signal2", .mode = O_WRONLY },
53 [
FD_MFC] = { .name =
"mfc", .mode = O_RDWR },
54 [
FD_MSS] = { .name =
"mss", .mode = O_RDWR },
57 static void *mapfileat(
int dir,
const char *filename,
int size)
62 fd_temp = openat(dir, filename, O_RDWR);
64 DEBUG_PRINTF(
"ERROR: Could not open SPE %s file.\n", filename);
68 ret = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_temp, 0);
74 static int setsignotify(
int dir,
const char *filename)
79 fd_sig = openat(dir, filename, O_RDWR);
83 if (write(fd_sig, &one,
sizeof(one)) !=
sizeof(one))
112 spe_fd_attr[fdesc].
name,
113 spe_fd_attr[fdesc].
mode);
143 static int free_spe_context(
struct spe_context *spe)
187 int i, aff_spe_fd = 0;
188 unsigned int spu_createflags = 0;
200 spe = malloc(
sizeof(*spe));
202 DEBUG_PRINTF(
"ERROR: Could not allocate spe context.\n");
205 memset(spe, 0,
sizeof(*spe));
210 "spe->base_private context.\n");
230 pthread_mutex_init(&priv->
fd_lock[i], NULL);
236 spu_createflags |= SPU_CREATE_ISOLATE | SPU_CREATE_NOSCHED;
240 spu_createflags |= SPU_CREATE_EVENTS_ENABLED;
243 spu_createflags |= SPU_CREATE_AFFINITY_SPU;
246 spu_createflags |= SPU_CREATE_AFFINITY_MEM;
250 sprintf(pathname,
"/spu/spethread-%i-%lu",
251 getpid(), (
unsigned long)spe);
253 sprintf(pathname,
"/spu/%s/spethread-%i-%lu",
260 priv->
fd_spe_dir = spu_create(pathname, spu_createflags,
261 S_IRUSR | S_IWUSR | S_IXUSR, aff_spe_fd);
264 int errno_saved = errno;
265 DEBUG_PRINTF(
"ERROR: Could not create SPE %s\n", pathname);
266 perror(
"spu_create()");
267 free_spe_context(spe);
269 switch (errno_saved) {
291 free_spe_context(spe);
335 free_spe_context(spe);
343 if (setsignotify(priv->
fd_spe_dir,
"signal1_type")) {
345 "signal1_type file.\n");
346 free_spe_context(spe);
353 if (setsignotify(priv->
fd_spe_dir,
"signal2_type")) {
355 "signal2_type file.\n");
356 free_spe_context(spe);
382 gctx = malloc(
sizeof(*gctx));
384 DEBUG_PRINTF(
"ERROR: Could not allocate spe context.\n");
387 memset(gctx, 0,
sizeof(*gctx));
389 pgctx = malloc(
sizeof(*pgctx));
391 DEBUG_PRINTF(
"ERROR: Could not allocate spe context.\n");
395 memset(pgctx, 0,
sizeof(*pgctx));
400 (
unsigned long)gctx);
401 sprintf(pathname,
"/spu/%s", gctx->base_private->gangname);
403 gctx->base_private->fd_gang_dir = spu_create(pathname, SPU_CREATE_GANG,
404 S_IRUSR | S_IWUSR | S_IXUSR);
406 if (gctx->base_private->fd_gang_dir < 0) {
407 DEBUG_PRINTF(
"ERROR: Could not create Gang %s\n", pathname);
408 free_spe_gang_context(gctx);
413 gctx->base_private->flags = flags;
420 int ret = free_spe_context(spe);
429 return free_spe_gang_context(gctx);