Skip to content

Commit d5a89ff

Browse files
committed
Add hugepage tests to dma dir
Signed-off-by: Jeremy Kerr <[email protected]>
1 parent 3a91bf0 commit d5a89ff

File tree

3 files changed

+321
-3
lines changed

3 files changed

+321
-3
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Testsuite for the Linux SPU filesystem
3+
*
4+
* Copyright (C) IBM Corporation, 2007
5+
*
6+
* Author: Jeremy Kerr <[email protected]>
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation; either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program; if not, write to the Free Software
20+
* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21+
*/
22+
#define _ATFILE_SOURCE
23+
24+
#include <stdlib.h>
25+
#include <stdio.h>
26+
#include <fcntl.h>
27+
#include <assert.h>
28+
#include <string.h>
29+
#include <sys/mman.h>
30+
31+
#include <test/spu_syscalls.h>
32+
#include <test/hw.h>
33+
34+
#define HUGEPAGE_FILE "/huge/03-hugepage"
35+
#define HUGEPAGE_SIZE (16 * 1024 * 1024)
36+
37+
/* map a hugepage, and DMA the (untouched) contents to the SPE. The SPE
38+
* should trigger a class1 interrup that ends up with the hugepage being
39+
* mapped */
40+
41+
#if 0
42+
/* area for PPE buffer address, stored in the first two words */
43+
.long 0x0
44+
.long 0x0
45+
.long 0x0
46+
.long 0x0
47+
48+
start:
49+
il r0,0x1000 /* LS address */
50+
lqa r1,0 /* PPE address */
51+
il r2,0x1000 /* transfer size */
52+
il r3,0 /* tag group ID */
53+
il r4,0x40 /* command ('get') */
54+
55+
/* do dma */
56+
wrch ch16,r0
57+
wrch ch17,r1
58+
shlqbyi r1,r1,4
59+
wrch ch18,r1
60+
wrch ch19,r2
61+
wrch ch20,r3
62+
wrch ch21,r4
63+
64+
/* wait for completion */
65+
il r5,1 /* mask for tag 0 */
66+
il r6,1 /* 0x1: any completion */
67+
68+
wrch ch22,r5
69+
wrch ch23,r6
70+
71+
rdch r7,ch24
72+
ceqi r8,r5,1
73+
brnz r8,exit /* error if our tag (1) isn't complete */
74+
stop 0x0
75+
exit:
76+
stop 0x1337
77+
78+
#endif
79+
static uint32_t spe_program[] = {
80+
0x00000000, /* stop */
81+
0x00000000, /* stop */
82+
0x00000000, /* stop */
83+
0x00000000, /* stop */
84+
/* start: */
85+
0x40880000, /* il r0,4096 # 1000 */
86+
0x30800001, /* lqa r1,0 */
87+
0x40880002, /* il r2,4096 # 1000 */
88+
0x40800003, /* il r3,0 */
89+
0x40802004, /* il r4,64 # 40 */
90+
0x21a00800, /* wrch $ch16,r0 */
91+
0x21a00881, /* wrch $ch17,r1 */
92+
0x3fe10081, /* shlqbyi r1,r1,4 */
93+
0x21a00901, /* wrch $ch18,r1 */
94+
0x21a00982, /* wrch $ch19,r2 */
95+
0x21a00a03, /* wrch $ch20,r3 */
96+
0x21a00a84, /* wrch $ch21,r4 */
97+
0x40800085, /* il r5,1 */
98+
0x40800086, /* il r6,1 */
99+
0x21a00b05, /* wrch $ch22,r5 */
100+
0x21a00b86, /* wrch $ch23,r6 */
101+
0x01a00c07, /* rdch r7,$ch24 */
102+
0x7c004288, /* ceqi r8,r5,1 */
103+
0x21000108, /* brnz r8,60 <exit> # 60 */
104+
0x00000000, /* stop */
105+
/* exit: */
106+
0x00001337, /* stop */
107+
};
108+
109+
110+
int main()
111+
{
112+
int ls_fd, hp_fd, ctx, rc;
113+
uint8_t *ls_map;
114+
uint8_t *hp_map;
115+
uint32_t entry;
116+
char *name = "/spu/03-hugepage-spe-faulted";
117+
118+
ctx = spu_create(name, 0, 0755);
119+
assert(ctx >= 0);
120+
121+
hp_fd = open(HUGEPAGE_FILE, O_RDWR | O_CREAT, 0600);
122+
if (hp_fd < 0) {
123+
perror("open");
124+
fprintf(stderr, "failed to open %s. are hugepages enabled? "
125+
"permissions?\n", HUGEPAGE_FILE);
126+
return EXIT_FAILURE;
127+
}
128+
unlink(HUGEPAGE_FILE);
129+
130+
hp_map = mmap(NULL, HUGEPAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
131+
hp_fd, 0);
132+
assert(hp_map != MAP_FAILED);
133+
134+
ls_fd = openat(ctx, "mem", O_RDWR);
135+
assert(ls_fd >= 0);
136+
137+
ls_map = mmap(NULL, LS_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
138+
ls_fd, 0);
139+
assert(ls_map != MAP_FAILED);
140+
141+
memcpy(ls_map, spe_program, sizeof(spe_program));
142+
143+
/* set the PPE address at the first 2 words of LS memory */
144+
*((uint64_t *)(ls_map)) = (unsigned long)hp_map;
145+
146+
entry = 0x10;
147+
rc = spu_run(ctx, &entry, NULL);
148+
149+
if (rc != 0x13370002) {
150+
fprintf(stderr, "Incorrect stop code: 0x%x\n", rc);
151+
return EXIT_FAILURE;
152+
}
153+
154+
return EXIT_SUCCESS;
155+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/*
2+
* Testsuite for the Linux SPU filesystem
3+
*
4+
* Copyright (C) IBM Corporation, 2007
5+
*
6+
* Author: Jeremy Kerr <[email protected]>
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation; either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program; if not, write to the Free Software
20+
* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21+
*/
22+
#define _ATFILE_SOURCE
23+
24+
#include <stdlib.h>
25+
#include <stdio.h>
26+
#include <fcntl.h>
27+
#include <assert.h>
28+
#include <string.h>
29+
#include <sys/mman.h>
30+
31+
#include <test/spu_syscalls.h>
32+
#include <test/hw.h>
33+
34+
#include "pattern.h"
35+
36+
#define HUGEPAGE_FILE "/huge/04-hugepage-ppe-faulted"
37+
#define HUGEPAGE_SIZE (16 * 1024 * 1024)
38+
39+
/* Using hugepages, dma one page from the PPE to SPE, and compare the local
40+
* store to the PPE buffer. */
41+
42+
43+
#if 0
44+
/* area for PPE buffer address, stored in the first two words */
45+
.long 0x0
46+
.long 0x0
47+
.long 0x0
48+
.long 0x0
49+
50+
start:
51+
il r0,0x1000 /* LS address */
52+
lqa r1,0 /* PPE address */
53+
il r2,0x1000 /* transfer size */
54+
il r3,0 /* tag group ID */
55+
il r4,0x40 /* command ('get') */
56+
57+
/* do dma */
58+
wrch ch16,r0
59+
wrch ch17,r1
60+
shlqbyi r1,r1,4
61+
wrch ch18,r1
62+
wrch ch19,r2
63+
wrch ch20,r3
64+
wrch ch21,r4
65+
66+
/* wait for completion */
67+
il r5,1 /* mask for tag 0 */
68+
il r6,1 /* 0x1: any completion */
69+
70+
wrch ch22,r5
71+
wrch ch23,r6
72+
73+
rdch r7,ch24
74+
ceqi r8,r5,1
75+
brnz r8,exit /* error if our tag (1) isn't complete */
76+
stop 0x0
77+
exit:
78+
stop 0x1337
79+
80+
#endif
81+
static uint32_t spe_program[] = {
82+
0x00000000, /* stop */
83+
0x00000000, /* stop */
84+
0x00000000, /* stop */
85+
0x00000000, /* stop */
86+
/* start: */
87+
0x40880000, /* il r0,4096 # 1000 */
88+
0x30800001, /* lqa r1,0 */
89+
0x40880002, /* il r2,4096 # 1000 */
90+
0x40800003, /* il r3,0 */
91+
0x40802004, /* il r4,64 # 40 */
92+
0x21a00800, /* wrch $ch16,r0 */
93+
0x21a00881, /* wrch $ch17,r1 */
94+
0x3fe10081, /* shlqbyi r1,r1,4 */
95+
0x21a00901, /* wrch $ch18,r1 */
96+
0x21a00982, /* wrch $ch19,r2 */
97+
0x21a00a03, /* wrch $ch20,r3 */
98+
0x21a00a84, /* wrch $ch21,r4 */
99+
0x40800085, /* il r5,1 */
100+
0x40800086, /* il r6,1 */
101+
0x21a00b05, /* wrch $ch22,r5 */
102+
0x21a00b86, /* wrch $ch23,r6 */
103+
0x01a00c07, /* rdch r7,$ch24 */
104+
0x7c004288, /* ceqi r8,r5,1 */
105+
0x21000108, /* brnz r8,60 <exit> # 60 */
106+
0x00000000, /* stop */
107+
/* exit: */
108+
0x00001337, /* stop */
109+
};
110+
111+
112+
int main()
113+
{
114+
int ls_fd, hp_fd, ctx, rc;
115+
uint8_t *ls_map;
116+
uint8_t *hp_map;
117+
uint32_t entry;
118+
char *name = "/spu/04-hugepage-ppe-faulted";
119+
120+
ctx = spu_create(name, 0, 0755);
121+
assert(ctx >= 0);
122+
123+
hp_fd = open(HUGEPAGE_FILE, O_RDWR | O_CREAT, 0600);
124+
if (hp_fd < 0) {
125+
perror("open");
126+
fprintf(stderr, "failed to open %s. are hugepages enabled? "
127+
"permissions?\n", HUGEPAGE_FILE);
128+
return EXIT_FAILURE;
129+
}
130+
unlink(HUGEPAGE_FILE);
131+
132+
hp_map = mmap(NULL, HUGEPAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
133+
hp_fd, 0);
134+
assert(hp_map != MAP_FAILED);
135+
136+
load_pattern(hp_map, 0x1000);
137+
138+
ls_fd = openat(ctx, "mem", O_RDWR);
139+
assert(ls_fd >= 0);
140+
141+
ls_map = mmap(NULL, LS_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
142+
ls_fd, 0);
143+
assert(ls_map != MAP_FAILED);
144+
145+
memcpy(ls_map, spe_program, sizeof(spe_program));
146+
147+
/* set the PPE address at the first 2 words of LS memory */
148+
*((uint64_t *)(ls_map)) = (unsigned long)hp_map;
149+
150+
entry = 0x10;
151+
rc = spu_run(ctx, &entry, NULL);
152+
153+
if (rc != 0x13370002) {
154+
fprintf(stderr, "Incorrect stop code: 0x%x\n", rc);
155+
return EXIT_FAILURE;
156+
}
157+
158+
if (check_pattern(ls_map + 0x1000, 0x1000)) {
159+
fprintf(stderr, "Pattern check failed\n");
160+
return EXIT_FAILURE;
161+
}
162+
163+
return EXIT_SUCCESS;
164+
}

tests/14-dma/Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# along with this program; if not, write to the Free Software
1919
# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2020

21-
obj += 01-spe-get 02-spe-put
21+
obj += 01-spe-get 02-spe-put 03-hugepage-spe-faulted 04-hugepage-ppe-faulted
2222

23-
01-spe-get: 01-spe-get.o pattern.o
24-
02-spe-put: 02-spe-put.o pattern.o
23+
$(obj): pattern.o

0 commit comments

Comments
 (0)