1 /* Copyright 2007-2014 Free Software Foundation, Inc.
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 3 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 This file is part of the gdb testsuite.
18 Contributed by Markus Deuling <deuling@de.ibm.com>.
19 Tests for 'info spu' commands. */
23 #include <sys/types.h>
26 #include <spu_mfcio.h>
29 /* PPE-assisted call interface. */
31 send_to_ppe (unsigned int signalcode
, unsigned int opcode
, void *data
)
33 __vector
unsigned int stopfunc
=
35 signalcode
, /* stop */
36 (opcode
<< 24) | (unsigned int) data
,
38 0x35000000 /* bi $0 */
41 void (*f
) (void) = (void *) &stopfunc
;
46 /* PPE-assisted call to mmap from SPU. */
48 mmap_ea (unsigned long long start
, size_t length
,
49 int prot
, int flags
, int fd
, off_t offset
)
53 unsigned long long start
__attribute__ ((aligned (16)));
54 size_t length
__attribute__ ((aligned (16)));
55 int prot
__attribute__ ((aligned (16)));
56 int flags
__attribute__ ((aligned (16)));
57 int fd
__attribute__ ((aligned (16)));
58 off_t offset
__attribute__ ((aligned (16)));
68 send_to_ppe (0x2101, 11, &args
);
72 /* This works only in a Linux environment with <= 1024 open
73 file descriptors for one process. Result is the file
74 descriptor for the current context if available. */
76 find_context_fd (void)
81 for (i
= 0; i
< 1024; i
++)
85 if (fstat (i
, &stat
) < 0)
87 if (S_ISDIR (stat
.st_mode
))
88 dir_fd
= dir_fd
== -1 ? i
: -2;
90 return dir_fd
< 0 ? -1 : dir_fd
;
93 /* Open the context file and return the file handler. */
95 open_context_file (int context_fd
, char *name
, int flags
)
102 sprintf (buf
, "/proc/self/fd/%d/%s", context_fd
, name
);
103 return open (buf
, flags
);
110 spu_write_event_mask (MFC_MULTI_SRC_SYNC_EVENT
); /* 0x1000 */ /* Marker Event */
111 spu_write_event_mask (MFC_PRIV_ATTN_EVENT
); /* 0x0800 */
112 spu_write_event_mask (MFC_LLR_LOST_EVENT
); /* 0x0400 */
113 spu_write_event_mask (MFC_SIGNAL_NOTIFY_1_EVENT
); /* 0x0200 */
114 spu_write_event_mask (MFC_SIGNAL_NOTIFY_2_EVENT
); /* 0x0100 */
115 spu_write_event_mask (MFC_OUT_MBOX_AVAILABLE_EVENT
); /* 0x0080 */
116 spu_write_event_mask (MFC_OUT_INTR_MBOX_AVAILABLE_EVENT
); /* 0x0040 */
117 spu_write_event_mask (MFC_DECREMENTER_EVENT
); /* 0x0020 */
118 spu_write_event_mask (MFC_IN_MBOX_AVAILABLE_EVENT
); /* 0x0010 */
119 spu_write_event_mask (MFC_COMMAND_QUEUE_AVAILABLE_EVENT
); /* 0x0008 */
120 spu_write_event_mask (MFC_LIST_STALL_NOTIFY_EVENT
); /* 0x0002 */
121 spu_write_event_mask (MFC_TAG_STATUS_UPDATE_EVENT
); /* 0x0001 */
129 #define MAP_FAILED (-1ULL)
130 #define PROT_READ 0x1
131 #define MAP_PRIVATE 0x002
133 static char buf
[BSIZE
] __attribute__ ((aligned (128)));
134 char *file
= "/var/tmp/tmp_buf";
137 unsigned long long src
;
139 /* Create a file and fill it with some bytes. */
140 fd
= open (file
, O_CREAT
| O_RDWR
| O_TRUNC
, 0777);
143 memset ((void *)buf
, '1', BSIZE
);
144 write (fd
, buf
, BSIZE
);
145 write (fd
, buf
, BSIZE
);
146 memset ((void *)buf
, 0, BSIZE
);
148 if (fstat (fd
, &fdstat
) != 0
152 src
= mmap_ea(0ULL, fdstat
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0);
153 if (src
== MAP_FAILED
)
156 /* Copy some data via DMA. */
157 mfc_get (&buf
, src
, BSIZE
, 5, 0, 0); /* Marker DMA */
158 mfc_write_tag_mask (1<<5); /* Marker DMAWait */
159 spu_mfcstat (MFC_TAG_UPDATE_ALL
);
161 /* Close the file. */
170 /* Write to SPU Outbound Mailbox. */
171 if (spu_stat_out_mbox ()) /* Marker Mbox */
172 spu_write_out_mbox (0x12345678);
174 /* Write to SPU Outbound Interrupt Mailbox. */
175 if (spu_stat_out_intr_mbox ())
176 spu_write_out_intr_mbox (0x12345678);
178 return 0; /* Marker MboxEnd */
185 int context_fd
= find_context_fd ();
188 buf
= 23; /* Marker Signal */
189 /* Write to signal1. */
190 fd
= open_context_file (context_fd
, "signal1", O_RDWR
);
191 if (fstat (fd
, &fdstat
) != 0)
193 ret
= write (fd
, buf
, sizeof (int));
194 close (fd
); /* Marker Signal1 */
196 /* Write to signal2. */
197 fd
= open_context_file (context_fd
, "signal2", O_RDWR
);
198 if (fstat (fd
, &fdstat
) != 0)
200 ret
= write (fd
, buf
, sizeof (int));
201 close (fd
); /* Marker Signal2 */
204 if (spu_stat_signal1 ())
205 ret
= spu_read_signal1 ();
208 if (spu_stat_signal2 ())
209 ret
= spu_read_signal2 (); /* Marker SignalRead */
215 main (unsigned long long speid
, unsigned long long argp
,
216 unsigned long long envp
)
221 res
= do_event_test ();
224 res
= do_dma_test ();
226 /* info spu mailbox */
227 res
= do_mailbox_test ();
229 /* info spu signal */
230 res
= do_signal_test ();