summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2007-12-11 12:40:58 -0800
committerIan Romanick <[email protected]>2007-12-11 12:43:50 -0800
commit9a0fe23d493dc9307d76f0a35cbe4f410ee3df28 (patch)
tree1f74ba9ca00ded31caf7d26e55ba707f4c81b0b1 /src/mesa
parentbfb43e8e79c3b0d85c1b459c5524619c8eb33280 (diff)
Port to libspe2
libspe is deprecated in Cell SDK 2.1, and it is removed in Cell SDK 3.0. This patch ports the existing libspe-based code to libspe2. Some error checking (eh-hem) would be nice.
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/pipe/cell/ppu/cell_flush.c4
-rw-r--r--src/mesa/pipe/cell/ppu/cell_spu.c83
-rw-r--r--src/mesa/pipe/cell/ppu/cell_spu.h14
-rw-r--r--src/mesa/pipe/cell/ppu/cell_surface.c6
4 files changed, 58 insertions, 49 deletions
diff --git a/src/mesa/pipe/cell/ppu/cell_flush.c b/src/mesa/pipe/cell/ppu/cell_flush.c
index e844d13f06c..39b72c435d5 100644
--- a/src/mesa/pipe/cell/ppu/cell_flush.c
+++ b/src/mesa/pipe/cell/ppu/cell_flush.c
@@ -43,12 +43,12 @@ cell_flush(struct pipe_context *pipe, unsigned flags)
/* Send CMD_FINISH to all SPUs */
for (i = 0; i < cell->num_spus; i++) {
- send_mbox_message(control_ps_area[i], CELL_CMD_FINISH);
+ send_mbox_message(spe_contexts[i], CELL_CMD_FINISH);
}
/* Wait for ack */
for (i = 0; i < cell->num_spus; i++) {
- uint k = wait_mbox_message(control_ps_area[i]);
+ uint k = wait_mbox_message(spe_contexts[i]);
assert(k == CELL_CMD_FINISH);
}
}
diff --git a/src/mesa/pipe/cell/ppu/cell_spu.c b/src/mesa/pipe/cell/ppu/cell_spu.c
index 37207c38d7d..7d41c660e4f 100644
--- a/src/mesa/pipe/cell/ppu/cell_spu.c
+++ b/src/mesa/pipe/cell/ppu/cell_spu.c
@@ -27,6 +27,7 @@
#include <cbe_mfc.h>
+#include <pthread.h>
#include "cell_spu.h"
#include "pipe/p_format.h"
@@ -43,9 +44,8 @@ helpful headers:
/**
* SPU/SPE handles, etc
*/
-speid_t speid[MAX_SPUS];
-spe_spu_control_area_t *control_ps_area[MAX_SPUS];
-
+spe_context_ptr_t spe_contexts[MAX_SPUS];
+pthread_t spe_threads[MAX_SPUS];
/**
* Data sent to SPUs
@@ -58,11 +58,9 @@ struct cell_command command[MAX_SPUS];
* Write a 1-word message to the given SPE mailbox.
*/
void
-send_mbox_message(spe_spu_control_area_t *ca, unsigned int msg)
+send_mbox_message(spe_context_ptr_t ctx, unsigned int msg)
{
- while (_spe_in_mbox_status(ca) < 1)
- ;
- _spe_in_mbox_write(ca, msg);
+ spe_in_mbox_write(ctx, &msg, 1, SPE_MBOX_ALL_BLOCKING);
}
@@ -70,13 +68,30 @@ send_mbox_message(spe_spu_control_area_t *ca, unsigned int msg)
* Wait for a 1-word message to arrive in given mailbox.
*/
uint
-wait_mbox_message(spe_spu_control_area_t *ca)
+wait_mbox_message(spe_context_ptr_t ctx)
+{
+ do {
+ unsigned data;
+ int count = spe_out_mbox_read(ctx, &data, 1);
+
+ if (count == 1) {
+ return data;
+ }
+
+ if (count < 0) {
+ /* error */ ;
+ }
+ } while (1);
+}
+
+
+static void *cell_thread_function(void *arg)
{
- uint k;
- while (_spe_out_mbox_status(ca) < 1)
- ;
- k = _spe_out_mbox_read(ca);
- return k;
+ struct cell_init_info *init = (struct cell_init_info *) arg;
+ unsigned entry = SPE_DEFAULT_ENTRY;
+
+ spe_context_run(spe_contexts[init->id], &entry, 0, init, NULL, NULL);
+ pthread_exit(NULL);
}
@@ -96,22 +111,17 @@ cell_start_spus(uint num_spus)
ASSERT_ALIGN16(&inits[0]);
ASSERT_ALIGN16(&inits[1]);
- /* XXX do we need to create a gid with spe_create_group()? */
-
for (i = 0; i < num_spus; i++) {
inits[i].id = i;
inits[i].num_spus = num_spus;
inits[i].cmd = &command[i];
- speid[i] = spe_create_thread(0, /* gid */
- &g3d_spu, /* spe program handle */
- &inits[i], /* argp */
- NULL, /* envp */
- -1, /* mask */
- SPE_MAP_PS/*0*/ ); /* flags */
+ spe_contexts[i] = spe_context_create(0, NULL);
- control_ps_area[i] = spe_get_ps_area(speid[i], SPE_CONTROL_AREA);
- assert(control_ps_area[i]);
+ spe_program_load(spe_contexts[i], &g3d_spu);
+
+ pthread_create(&spe_threads[i], NULL, cell_thread_function,
+ & inits[i]);
}
}
@@ -124,14 +134,15 @@ finish_all(uint num_spus)
uint i;
for (i = 0; i < num_spus; i++) {
- send_mbox_message(control_ps_area[i], CELL_CMD_FINISH);
+ send_mbox_message(spe_contexts[i], CELL_CMD_FINISH);
}
for (i = 0; i < num_spus; i++) {
/* wait for mbox message */
unsigned k;
- while (_spe_out_mbox_status(control_ps_area[i]) < 1)
+
+ while (spe_out_mbox_read(spe_contexts[i], &k, 1) < 1)
;
- k = _spe_out_mbox_read(control_ps_area[i]);
+
assert(k == CELL_CMD_FINISH);
}
}
@@ -154,12 +165,12 @@ test_spus(struct cell_context *cell)
command[i].fb.width = surf->width;
command[i].fb.height = surf->height;
command[i].fb.format = PIPE_FORMAT_A8R8G8B8_UNORM;
- send_mbox_message(control_ps_area[i], CELL_CMD_FRAMEBUFFER);
+ send_mbox_message(spe_contexts[i], CELL_CMD_FRAMEBUFFER);
}
for (i = 0; i < cell->num_spus; i++) {
command[i].clear.value = 0xff880044; /* XXX */
- send_mbox_message(control_ps_area[i], CELL_CMD_CLEAR_TILES);
+ send_mbox_message(spe_contexts[i], CELL_CMD_CLEAR_TILES);
}
finish_all(cell->num_spus);
@@ -171,7 +182,7 @@ test_spus(struct cell_context *cell)
}
for (i = 0; i < cell->num_spus; i++) {
- send_mbox_message(control_ps_area[i], CELL_CMD_EXIT);
+ send_mbox_message(spe_contexts[i], CELL_CMD_EXIT);
}
}
@@ -182,10 +193,11 @@ test_spus(struct cell_context *cell)
void
wait_spus(uint num_spus)
{
- int i, status;
+ unsigned i;
+ void *value;
for (i = 0; i < num_spus; i++) {
- spe_wait( speid[i], &status, 1 );
+ pthread_join(spe_threads[i], &value);
}
}
@@ -196,14 +208,11 @@ wait_spus(uint num_spus)
void
cell_spu_exit(struct cell_context *cell)
{
- uint i;
- int status;
+ unsigned i;
for (i = 0; i < cell->num_spus; i++) {
- send_mbox_message(control_ps_area[i], CELL_CMD_EXIT);
+ send_mbox_message(spe_contexts[i], CELL_CMD_EXIT);
}
- for (i = 0; i < cell->num_spus; i++) {
- spe_wait( speid[i], &status, 1 );
- }
+ wait_spus(cell->num_spus);
}
diff --git a/src/mesa/pipe/cell/ppu/cell_spu.h b/src/mesa/pipe/cell/ppu/cell_spu.h
index f030be45fca..09d5e23a88d 100644
--- a/src/mesa/pipe/cell/ppu/cell_spu.h
+++ b/src/mesa/pipe/cell/ppu/cell_spu.h
@@ -29,7 +29,7 @@
#define CELL_SPU
-#include <libspe.h>
+#include <libspe2.h>
#include <libmisc.h>
#include "pipe/cell/common.h"
@@ -42,8 +42,8 @@
* SPU/SPE handles, etc
*/
extern spe_program_handle_t g3d_spu;
-extern speid_t speid[MAX_SPUS];
-extern spe_spu_control_area_t *control_ps_area[MAX_SPUS];
+extern spe_context_ptr_t spe_contexts[MAX_SPUS];
+extern pthread_t spe_threads[MAX_SPUS];
/**
@@ -53,11 +53,11 @@ extern struct cell_init_info inits[MAX_SPUS];
extern struct cell_command command[MAX_SPUS];
-void
-send_mbox_message(spe_spu_control_area_t *ca, unsigned int msg);
+extern void
+send_mbox_message(spe_context_ptr_t ctx, unsigned int msg);
-uint
-wait_mbox_message(spe_spu_control_area_t *ca);
+extern uint
+wait_mbox_message(spe_context_ptr_t ctx);
void
diff --git a/src/mesa/pipe/cell/ppu/cell_surface.c b/src/mesa/pipe/cell/ppu/cell_surface.c
index 59cd43e630b..ab20adb06d2 100644
--- a/src/mesa/pipe/cell/ppu/cell_surface.c
+++ b/src/mesa/pipe/cell/ppu/cell_surface.c
@@ -78,13 +78,13 @@ cell_clear_surface(struct pipe_context *pipe, struct pipe_surface *ps,
command[i].fb.width = ps->width;
command[i].fb.height = ps->height;
command[i].fb.format = ps->format;
- send_mbox_message(control_ps_area[i], CELL_CMD_FRAMEBUFFER);
+ send_mbox_message(spe_contexts[i], CELL_CMD_FRAMEBUFFER);
}
for (i = 0; i < cell->num_spus; i++) {
/* XXX clear color varies per-SPU for debugging */
command[i].clear.value = clearValue | (i << 21);
- send_mbox_message(control_ps_area[i], CELL_CMD_CLEAR_TILES);
+ send_mbox_message(spe_contexts[i], CELL_CMD_CLEAR_TILES);
}
#if 1
@@ -103,7 +103,7 @@ cell_clear_surface(struct pipe_context *pipe, struct pipe_surface *ps,
/* XXX color varies per SPU */
command[i].tri.color = 0xffff00 | ((i*40)<<24); /* yellow */
- send_mbox_message(control_ps_area[i], CELL_CMD_TRIANGLE);
+ send_mbox_message(spe_contexts[i], CELL_CMD_TRIANGLE);
}
#endif
}