annotate src/video/ps3/SDL_ps3video.c @ 3142:c146645a770e gsoc2009_ps3

Roughly working framebuffer.
author Martin Lowinski <martin@goldtopf.org>
date Thu, 04 Jun 2009 07:02:15 +0000
parents 3df74541339b
children 0d8d1f870964
rev   line source
3141
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
1 /*
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
4
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
9
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
13 Lesser General Public License for more details.
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
14
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
18
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
19 Sam Lantinga
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
20 slouken@libsdl.org
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
21 */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
22 #include "SDL_config.h"
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
23
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
24 /* SDL PS3 video driver implementation based on dummy video driver
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
25 *
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
26 * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
27 * of this was cut-and-pasted from Stephane Peter's work in the AAlib
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
28 * SDL video driver. Renamed to "DUMMY" by Sam Lantinga.
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
29 */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
30
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
31 #include "SDL_video.h"
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
32 #include "SDL_mouse.h"
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
33 #include "../SDL_sysvideo.h"
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
34 #include "../SDL_pixels_c.h"
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
35 #include "../../events/SDL_events_c.h"
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
36 #include "spulibs/spu_common.h"
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
37
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
38 #include "SDL_ps3video.h"
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
39 #include "SDL_ps3events_c.h"
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
40 #include "SDL_ps3render_c.h"
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
41
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
42 #include <fcntl.h>
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
43 #include <linux/fb.h>
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
44 #include <asm/ps3fb.h>
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
45 #include <libspe2.h>
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
46 #include <sys/mman.h>
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
47
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
48 #define PS3VID_DRIVER_NAME "ps3"
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
49
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
50 /* Initialization/Query functions */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
51 static int PS3_VideoInit(_THIS);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
52 static int PS3_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
53 static void PS3_VideoQuit(_THIS);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
54
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
55 /* SPU specific functions */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
56 int SPE_Start(_THIS, spu_data_t * spe_data);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
57 int SPE_Stop(_THIS, spu_data_t * spe_data);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
58 int SPE_Boot(_THIS, spu_data_t * spe_data);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
59 int SPE_Shutdown(_THIS, spu_data_t * spe_data);
3142
c146645a770e Roughly working framebuffer.
Martin Lowinski <martin@goldtopf.org>
parents: 3141
diff changeset
60 int SPE_SendMsg(spu_data_t * spe_data, unsigned int msg);
c146645a770e Roughly working framebuffer.
Martin Lowinski <martin@goldtopf.org>
parents: 3141
diff changeset
61 int SPE_WaitForMsg(spu_data_t * spe_data, unsigned int msg);
3141
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
62 void SPE_RunContext(void *thread_argp);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
63
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
64 /* Stores the SPE executable name of fb_writer_spu */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
65 extern spe_program_handle_t fb_writer_spu;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
66
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
67 /* PS3 driver bootstrap functions */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
68
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
69 static int
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
70 PS3_Available(void)
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
71 {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
72 deprintf(1, "PS3_Available()\n");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
73 const char *envr = SDL_getenv("SDL_VIDEODRIVER");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
74 if ((envr) && (SDL_strcmp(envr, PS3VID_DRIVER_NAME) == 0)) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
75 return (1);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
76 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
77
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
78 return (0);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
79 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
80
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
81 static void
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
82 PS3_DeleteDevice(SDL_VideoDevice * device)
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
83 {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
84 deprintf(1, "PS3_DeleteDevice()\n");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
85 SDL_free(device->driverdata);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
86 SDL_free(device);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
87 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
88
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
89 static SDL_VideoDevice *
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
90 PS3_CreateDevice(int devindex)
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
91 {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
92 deprintf(1, "PS3_CreateDevice()\n");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
93 SDL_VideoDevice *device;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
94 SDL_VideoData *data;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
95
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
96 /* Initialize all variables that we clean on shutdown */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
97 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
98 if (!device) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
99 SDL_OutOfMemory();
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
100 if (device) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
101 SDL_free(device);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
102 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
103 return (0);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
104 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
105 data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
106 if (!data) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
107 SDL_OutOfMemory();
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
108 SDL_free(device);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
109 return (0);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
110 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
111 device->driverdata = data;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
112
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
113 /* Set the function pointers */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
114 device->VideoInit = PS3_VideoInit;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
115 device->VideoQuit = PS3_VideoQuit;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
116 device->SetDisplayMode = PS3_SetDisplayMode;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
117 device->PumpEvents = PS3_PumpEvents;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
118
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
119 device->free = PS3_DeleteDevice;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
120
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
121 return device;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
122 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
123
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
124 VideoBootStrap PS3_bootstrap = {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
125 PS3VID_DRIVER_NAME, "SDL PS3 Cell video driver",
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
126 PS3_Available, PS3_CreateDevice
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
127 };
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
128
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
129
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
130 int
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
131 PS3_VideoInit(_THIS)
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
132 {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
133 deprintf(1, "PS3_VideoInit()\n");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
134
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
135 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
136 SDL_DisplayMode mode;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
137
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
138 /* Use a fake 32-bpp desktop mode */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
139 mode.format = SDL_PIXELFORMAT_RGB888;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
140 //mode.w = 1024;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
141 //mode.h = 768;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
142 mode.w = 1920;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
143 mode.h = 1080;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
144 mode.refresh_rate = 0;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
145 mode.driverdata = NULL;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
146 SDL_AddBasicVideoDisplay(&mode);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
147 SDL_AddRenderDriver(0, &SDL_PS3_RenderDriver);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
148
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
149 SDL_zero(mode);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
150 SDL_AddDisplayMode(0, &mode);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
151
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
152 /*
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
153 *PS3 stuff
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
154 */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
155
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
156 /* Create SPU fb_parms and thread structure */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
157 data->fb_parms = (struct fb_writer_parms_t *)
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
158 memalign(16, sizeof(struct fb_writer_parms_t));
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
159 data->fb_thread_data = (spu_data_t *) malloc(sizeof(spu_data_t));
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
160 if (data->fb_parms == NULL || data->fb_thread_data == NULL) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
161 SDL_OutOfMemory();
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
162 return -1;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
163 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
164 data->fb_thread_data->program = fb_writer_spu;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
165 data->fb_thread_data->program_name = "fb_writer_spu";
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
166 data->fb_thread_data->argp = (void *)data->fb_parms;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
167 data->fb_thread_data->keepalive = 1;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
168 data->fb_thread_data->booted = 0;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
169
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
170 SPE_Start(_this, data->fb_thread_data);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
171
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
172 /* Open the device */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
173 data->fbdev = open(PS3DEV, O_RDWR);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
174 if (data->fbdev < 0) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
175 SDL_SetError("[PS3] Unable to open device %s", PS3DEV);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
176 return -1;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
177 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
178
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
179 /* Take control of frame buffer from kernel, for details see
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
180 * http://felter.org/wesley/files/ps3/linux-20061110-docs/ApplicationProgrammingEnvironment.html
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
181 * kernel will no longer flip the screen itself
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
182 */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
183 ioctl(data->fbdev, PS3FB_IOCTL_ON, 0);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
184
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
185 /* Unblank screen */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
186 ioctl(data->fbdev, FBIOBLANK, 0);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
187
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
188 struct fb_fix_screeninfo fb_finfo;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
189 if (ioctl(data->fbdev, FBIOGET_FSCREENINFO, &fb_finfo)) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
190 SDL_SetError("[PS3] Can't get fixed screeninfo");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
191 return (0);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
192 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
193
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
194 /* Note: on PS3, fb_finfo.smem_len is enough for double buffering */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
195 if ((data->frame_buffer = (uint8_t *)mmap(0, fb_finfo.smem_len,
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
196 PROT_READ | PROT_WRITE, MAP_SHARED,
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
197 data->fbdev, 0)) == (uint8_t *) - 1) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
198 SDL_SetError("[PS3] Can't mmap for %s", PS3DEV);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
199 return (0);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
200 } else {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
201 //current->flags |= SDL_DOUBLEBUF;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
202 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
203
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
204 /* Blank screen */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
205 memset(data->frame_buffer, 0x00, fb_finfo.smem_len);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
206
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
207 /* We're done! */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
208 return 0;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
209 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
210
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
211 static int
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
212 PS3_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
213 {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
214 deprintf(1, "PS3_SetDisplayMode()\n");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
215 return 0;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
216 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
217
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
218 void
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
219 PS3_VideoQuit(_THIS)
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
220 {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
221 deprintf(1, "PS3_VideoQuit()\n");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
222 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
223 if (data->frame_buffer) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
224 struct fb_fix_screeninfo fb_finfo;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
225 if (ioctl(data->fbdev, FBIOGET_FSCREENINFO, &fb_finfo) != -1) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
226 munmap(data->frame_buffer, fb_finfo.smem_len);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
227 data->frame_buffer = 0;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
228 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
229 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
230
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
231 if (data->fb_parms)
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
232 free((void *)data->fb_parms);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
233 if (data->fb_thread_data) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
234 SPE_Shutdown(_this, data->fb_thread_data);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
235 free((void *)data->fb_thread_data);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
236 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
237 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
238
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
239
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
240 /*
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
241 * SPE handling
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
242 */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
243
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
244 /* Start the SPE thread */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
245 int SPE_Start(_THIS, spu_data_t * spe_data)
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
246 {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
247 deprintf(2, "[PS3->SPU] Start SPE: %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
248 if (!(spe_data->booted))
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
249 SPE_Boot(_this, spe_data);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
250
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
251 /* To allow re-running of context, spe_ctx_entry has to be set before each call */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
252 spe_data->entry = SPE_DEFAULT_ENTRY;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
253 spe_data->error_code = 0;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
254
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
255 /* Create SPE thread and run */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
256 deprintf(2, "[PS3->SPU] Create Thread: %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
257 if (pthread_create
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
258 (&spe_data->thread, NULL, (void *)&SPE_RunContext, (void *)spe_data)) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
259 deprintf(2, "[PS3->SPU] Could not create pthread for spe: %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
260 SDL_SetError("[PS3->SPU] Could not create pthread for spe");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
261 return -1;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
262 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
263
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
264 if (spe_data->keepalive)
3142
c146645a770e Roughly working framebuffer.
Martin Lowinski <martin@goldtopf.org>
parents: 3141
diff changeset
265 SPE_WaitForMsg(spe_data, SPU_READY);
3141
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
266 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
267
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
268
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
269 /* Stop the SPE thread */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
270 int SPE_Stop(_THIS, spu_data_t * spe_data)
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
271 {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
272 deprintf(2, "[PS3->SPU] Stop SPE: %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
273 /* Wait for SPE thread to complete */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
274 deprintf(2, "[PS3->SPU] Wait for SPE thread to complete: %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
275 if (pthread_join(spe_data->thread, NULL)) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
276 deprintf(2, "[PS3->SPU] Failed joining the thread: %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
277 SDL_SetError("[PS3->SPU] Failed joining the thread");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
278 return -1;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
279 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
280
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
281 return 0;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
282 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
283
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
284 /* Create SPE context and load program */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
285 int SPE_Boot(_THIS, spu_data_t * spe_data)
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
286 {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
287 /* Create SPE context */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
288 deprintf(2, "[PS3->SPU] Create SPE Context: %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
289 spe_data->ctx = spe_context_create(0, NULL);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
290 if (spe_data->ctx == NULL) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
291 deprintf(2, "[PS3->SPU] Failed creating SPE context: %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
292 SDL_SetError("[PS3->SPU] Failed creating SPE context");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
293 return -1;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
294 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
295
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
296 /* Load SPE object into SPE local store */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
297 deprintf(2, "[PS3->SPU] Load Program into SPE: %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
298 if (spe_program_load(spe_data->ctx, &spe_data->program)) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
299 deprintf(2, "[PS3->SPU] Failed loading program into SPE context: %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
300 SDL_SetError
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
301 ("[PS3->SPU] Failed loading program into SPE context");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
302 return -1;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
303 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
304 spe_data->booted = 1;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
305 deprintf(2, "[PS3->SPU] SPE boot successful\n");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
306
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
307 return 0;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
308 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
309
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
310 /* (Stop and) shutdown the SPE */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
311 int SPE_Shutdown(_THIS, spu_data_t * spe_data)
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
312 {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
313 if (spe_data->keepalive && spe_data->booted) {
3142
c146645a770e Roughly working framebuffer.
Martin Lowinski <martin@goldtopf.org>
parents: 3141
diff changeset
314 SPE_SendMsg(spe_data, SPU_EXIT);
3141
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
315 SPE_Stop(_this, spe_data);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
316 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
317
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
318 /* Destroy SPE context */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
319 deprintf(2, "[PS3->SPU] Destroy SPE context: %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
320 if (spe_context_destroy(spe_data->ctx)) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
321 deprintf(2, "[PS3->SPU] Failed destroying context: %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
322 SDL_SetError("[PS3->SPU] Failed destroying context");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
323 return -1;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
324 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
325 deprintf(2, "[PS3->SPU] SPE shutdown successful: %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
326 return 0;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
327 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
328
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
329 /* Send message to the SPE via mailboxe */
3142
c146645a770e Roughly working framebuffer.
Martin Lowinski <martin@goldtopf.org>
parents: 3141
diff changeset
330 int SPE_SendMsg(spu_data_t * spe_data, unsigned int msg)
3141
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
331 {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
332 deprintf(2, "[PS3->SPU] Sending message %u to %s\n", msg, spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
333 /* Send one message, block until message was sent */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
334 unsigned int spe_in_mbox_msgs[1];
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
335 spe_in_mbox_msgs[0] = msg;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
336 int in_mbox_write = spe_in_mbox_write(spe_data->ctx, spe_in_mbox_msgs, 1, SPE_MBOX_ALL_BLOCKING);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
337
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
338 if (1 > in_mbox_write) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
339 deprintf(2, "[PS3->SPU] No message could be written to %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
340 SDL_SetError("[PS3->SPU] No message could be written");
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
341 return -1;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
342 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
343 return 0;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
344 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
345
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
346
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
347 /* Read 1 message from SPE, block until at least 1 message was received */
3142
c146645a770e Roughly working framebuffer.
Martin Lowinski <martin@goldtopf.org>
parents: 3141
diff changeset
348 int SPE_WaitForMsg(spu_data_t * spe_data, unsigned int msg)
3141
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
349 {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
350 deprintf(2, "[PS3->SPU] Waiting for message from %s\n", spe_data->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
351 unsigned int out_messages[1];
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
352 while (!spe_out_mbox_status(spe_data->ctx));
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
353 int mbox_read = spe_out_mbox_read(spe_data->ctx, out_messages, 1);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
354 deprintf(2, "[PS3->SPU] Got message from %s, message was %u\n", spe_data->program_name, out_messages[0]);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
355 if (out_messages[0] == msg)
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
356 return 0;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
357 else
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
358 return -1;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
359 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
360
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
361 /* Re-runnable invocation of the spe_context_run call */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
362 void SPE_RunContext(void *thread_argp)
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
363 {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
364 /* argp is the pointer to argument to be passed to the SPE program */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
365 spu_data_t *args = (spu_data_t *) thread_argp;
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
366 deprintf(3, "[PS3->SPU] void* argp=0x%x\n", (unsigned int)args->argp);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
367
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
368 /* Run it.. */
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
369 deprintf(2, "[PS3->SPU] Run SPE program: %s\n", args->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
370 if (spe_context_run
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
371 (args->ctx, &args->entry, 0, (void *)args->argp, NULL,
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
372 NULL) < 0) {
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
373 deprintf(2, "[PS3->SPU] Failed running SPE context: %s\n", args->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
374 SDL_SetError("[PS3->SPU] Failed running SPE context: %s", args->program_name);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
375 exit(1);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
376 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
377
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
378 pthread_exit(NULL);
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
379 }
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
380
3df74541339b Added ps3 video driver based on the dummy driver.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
381 /* vi: set ts=4 sw=4 expandtab: */