1*433d6423SLionel Sambuc #include "inc.h"
2*433d6423SLionel Sambuc
3*433d6423SLionel Sambuc char buf_buf[BUF_SIZE + CLICK_SIZE];
4*433d6423SLionel Sambuc
5*433d6423SLionel Sambuc endpoint_t ep_granter;
6*433d6423SLionel Sambuc int gid;
7*433d6423SLionel Sambuc char *buf;
8*433d6423SLionel Sambuc
9*433d6423SLionel Sambuc /*===========================================================================*
10*433d6423SLionel Sambuc * test *
11*433d6423SLionel Sambuc *===========================================================================*/
test(size_t size)12*433d6423SLionel Sambuc int test(size_t size)
13*433d6423SLionel Sambuc {
14*433d6423SLionel Sambuc u32_t low1, high1;
15*433d6423SLionel Sambuc u32_t low2, high2;
16*433d6423SLionel Sambuc int r;
17*433d6423SLionel Sambuc
18*433d6423SLionel Sambuc /* Timing. */
19*433d6423SLionel Sambuc read_tsc(&high1, &low1);
20*433d6423SLionel Sambuc r = sys_safecopyfrom(ep_granter, gid, 0, (long)buf, size);
21*433d6423SLionel Sambuc read_tsc(&high2, &low2);
22*433d6423SLionel Sambuc if(r != OK) {
23*433d6423SLionel Sambuc printf("REQUESTOR: error in safecopy: %d\n", r);
24*433d6423SLionel Sambuc return r;
25*433d6423SLionel Sambuc }
26*433d6423SLionel Sambuc printf("REQUESTOR: SAFECOPY 0x%-8x - %d\n", size, low2 - low1);
27*433d6423SLionel Sambuc
28*433d6423SLionel Sambuc /* Test. */
29*433d6423SLionel Sambuc if(buf[0] != BUF_START) {
30*433d6423SLionel Sambuc printf("REQUESTOR: error in safecopy!\n");
31*433d6423SLionel Sambuc printf(" size, value: %d, %d\n", size, buf[0]);
32*433d6423SLionel Sambuc return r;
33*433d6423SLionel Sambuc }
34*433d6423SLionel Sambuc
35*433d6423SLionel Sambuc return OK;
36*433d6423SLionel Sambuc }
37*433d6423SLionel Sambuc
38*433d6423SLionel Sambuc /* SEF functions and variables. */
39*433d6423SLionel Sambuc static void sef_local_startup(void);
40*433d6423SLionel Sambuc
41*433d6423SLionel Sambuc /*===========================================================================*
42*433d6423SLionel Sambuc * main *
43*433d6423SLionel Sambuc *===========================================================================*/
main(int argc,char ** argv)44*433d6423SLionel Sambuc int main(int argc, char **argv)
45*433d6423SLionel Sambuc {
46*433d6423SLionel Sambuc endpoint_t ep_self;
47*433d6423SLionel Sambuc int fid_send, fid_get;
48*433d6423SLionel Sambuc int i;
49*433d6423SLionel Sambuc
50*433d6423SLionel Sambuc /* SEF local startup. */
51*433d6423SLionel Sambuc env_setargs(argc, argv);
52*433d6423SLionel Sambuc sef_local_startup();
53*433d6423SLionel Sambuc
54*433d6423SLionel Sambuc /* Prepare work. */
55*433d6423SLionel Sambuc buf = (char*) CLICK_CEIL(buf_buf);
56*433d6423SLionel Sambuc fid_get = open(FIFO_GRANTOR, O_RDONLY);
57*433d6423SLionel Sambuc fid_send = open(FIFO_REQUESTOR, O_WRONLY);
58*433d6423SLionel Sambuc if(fid_get < 0 || fid_send < 0) {
59*433d6423SLionel Sambuc printf("REQUESTOR: can't open fifo files.\n");
60*433d6423SLionel Sambuc return 1;
61*433d6423SLionel Sambuc }
62*433d6423SLionel Sambuc
63*433d6423SLionel Sambuc /* Sending the endpoint to the granter, in order to let him
64*433d6423SLionel Sambuc * create the grant.
65*433d6423SLionel Sambuc */
66*433d6423SLionel Sambuc ep_self = sef_self();
67*433d6423SLionel Sambuc write(fid_send, &ep_self, sizeof(ep_self));
68*433d6423SLionel Sambuc dprint(("REQUESTOR: sending my endpoint: %d\n", ep_self));
69*433d6423SLionel Sambuc
70*433d6423SLionel Sambuc /* Getting the granter's endpoint and gid. */
71*433d6423SLionel Sambuc read(fid_get, &ep_granter, sizeof(ep_granter));
72*433d6423SLionel Sambuc read(fid_get, &gid, sizeof(gid));
73*433d6423SLionel Sambuc dprint(("REQUESTOR: getting granter's endpoint %d and gid %d\n",
74*433d6423SLionel Sambuc ep_granter, gid));
75*433d6423SLionel Sambuc
76*433d6423SLionel Sambuc /* Test SAFECOPY. */
77*433d6423SLionel Sambuc for(i = 0; i <= TEST_PAGE_SHIFT; i++) {
78*433d6423SLionel Sambuc if(test(1 << i) != OK)
79*433d6423SLionel Sambuc break;
80*433d6423SLionel Sambuc }
81*433d6423SLionel Sambuc
82*433d6423SLionel Sambuc /* Notify grantor we are done. */
83*433d6423SLionel Sambuc FIFO_NOTIFY(fid_send);
84*433d6423SLionel Sambuc
85*433d6423SLionel Sambuc return 0;
86*433d6423SLionel Sambuc }
87*433d6423SLionel Sambuc
88*433d6423SLionel Sambuc /*===========================================================================*
89*433d6423SLionel Sambuc * sef_local_startup *
90*433d6423SLionel Sambuc *===========================================================================*/
sef_local_startup()91*433d6423SLionel Sambuc static void sef_local_startup()
92*433d6423SLionel Sambuc {
93*433d6423SLionel Sambuc /* Let SEF perform startup. */
94*433d6423SLionel Sambuc sef_startup();
95*433d6423SLionel Sambuc }
96*433d6423SLionel Sambuc
97