Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / gallium / drivers / cell / spu / spu_main.c
1 /**************************************************************************
2  * 
3  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4  * All Rights Reserved.
5  * 
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  * 
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  * 
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  * 
26  **************************************************************************/
27
28
29 /* main() for Cell SPU code */
30
31
32 #include <stdio.h>
33 #include <libmisc.h>
34
35 #include "pipe/p_defines.h"
36
37 #include "spu_funcs.h"
38 #include "spu_command.h"
39 #include "spu_main.h"
40 #include "spu_per_fragment_op.h"
41 #include "spu_texture.h"
42 //#include "spu_test.h"
43 #include "cell/common.h"
44
45
46 /*
47 helpful headers:
48 /usr/lib/gcc/spu/4.1.1/include/spu_mfcio.h
49 /opt/cell/sdk/usr/include/libmisc.h
50 */
51
52 struct spu_global spu;
53
54
55 static void
56 one_time_init(void)
57 {
58    memset(spu.ctile_status, TILE_STATUS_DEFINED, sizeof(spu.ctile_status));
59    memset(spu.ztile_status, TILE_STATUS_DEFINED, sizeof(spu.ztile_status));
60    invalidate_tex_cache();
61 }
62
63 /* In some versions of the SDK the SPE main takes 'unsigned long' as a
64  * parameter.  In others it takes 'unsigned long long'.  Use a define to
65  * select between the two.
66  */
67 #ifdef SPU_MAIN_PARAM_LONG_LONG
68 typedef unsigned long long main_param_t;
69 #else
70 typedef unsigned long main_param_t;
71 #endif
72
73 /**
74  * SPE entrypoint.
75  */
76 int
77 main(main_param_t speid, main_param_t argp)
78 {
79    int tag = 0;
80
81    (void) speid;
82
83    ASSERT(sizeof(tile_t) == TILE_SIZE * TILE_SIZE * 4);
84    ASSERT(sizeof(struct cell_command_render) % 8 == 0);
85    ASSERT(sizeof(struct cell_command_fragment_ops) % 8 == 0);
86    ASSERT(((unsigned long) &spu.fragment_program_code) % 8 == 0);
87
88    one_time_init();
89    spu_command_init();
90
91    D_PRINTF(CELL_DEBUG_CMD, "main() speid=%lu\n", (unsigned long) speid);
92    D_PRINTF(CELL_DEBUG_FRAGMENT_OP_FALLBACK, "using fragment op fallback\n");
93
94    /* get initialization data */
95    mfc_get(&spu.init,  /* dest */
96            (unsigned int) argp, /* src */
97            sizeof(struct cell_init_info), /* bytes */
98            tag,
99            0, /* tid */
100            0  /* rid */);
101    wait_on_mask( 1 << tag );
102
103    if (spu.init.id == 0) {
104       return_function_info();
105    }
106
107 #if 0
108    if (spu.init.id==0)
109       spu_test_misc(spu.init.id);
110 #endif
111
112    command_loop();
113
114    spu_command_close();
115
116    return 0;
117 }