|
| 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 | +} |
0 commit comments