Commit b62a39a1 authored by Karen Xie's avatar Karen Xie

XDMA dma_from/to_device add option -k for memory aperture

parent d229a934
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
static struct option const long_opts[] = { static struct option const long_opts[] = {
{"device", required_argument, NULL, 'd'}, {"device", required_argument, NULL, 'd'},
{"address", required_argument, NULL, 'a'}, {"address", required_argument, NULL, 'a'},
{"aperture", required_argument, NULL, 'k'},
{"size", required_argument, NULL, 's'}, {"size", required_argument, NULL, 's'},
{"offset", required_argument, NULL, 'o'}, {"offset", required_argument, NULL, 'o'},
{"count", required_argument, NULL, 'c'}, {"count", required_argument, NULL, 'c'},
...@@ -44,8 +45,9 @@ static struct option const long_opts[] = { ...@@ -44,8 +45,9 @@ static struct option const long_opts[] = {
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
static int test_dma(char *devname, uint64_t addr, uint64_t size, static int test_dma(char *devname, uint64_t addr, uint64_t aperture,
uint64_t offset, uint64_t count, char *ofname); uint64_t size, uint64_t offset, uint64_t count,
char *ofname);
static int no_write = 0; static int no_write = 0;
static void usage(const char *name) static void usage(const char *name)
...@@ -61,6 +63,9 @@ static void usage(const char *name) ...@@ -61,6 +63,9 @@ static void usage(const char *name)
fprintf(stdout, " -%c (--%s) the start address on the AXI bus\n", fprintf(stdout, " -%c (--%s) the start address on the AXI bus\n",
long_opts[i].val, long_opts[i].name); long_opts[i].val, long_opts[i].name);
i++; i++;
fprintf(stdout, " -%c (--%s) memory address aperture\n",
long_opts[i].val, long_opts[i].name);
i++;
fprintf(stdout, fprintf(stdout,
" -%c (--%s) size of a single transfer in bytes, default %d.\n", " -%c (--%s) size of a single transfer in bytes, default %d.\n",
long_opts[i].val, long_opts[i].name, SIZE_DEFAULT); long_opts[i].val, long_opts[i].name, SIZE_DEFAULT);
...@@ -88,12 +93,13 @@ int main(int argc, char *argv[]) ...@@ -88,12 +93,13 @@ int main(int argc, char *argv[])
int cmd_opt; int cmd_opt;
char *device = DEVICE_NAME_DEFAULT; char *device = DEVICE_NAME_DEFAULT;
uint64_t address = 0; uint64_t address = 0;
uint64_t aperture = 0;
uint64_t size = SIZE_DEFAULT; uint64_t size = SIZE_DEFAULT;
uint64_t offset = 0; uint64_t offset = 0;
uint64_t count = COUNT_DEFAULT; uint64_t count = COUNT_DEFAULT;
char *ofname = NULL; char *ofname = NULL;
while ((cmd_opt = getopt_long(argc, argv, "vhxc:f:d:a:s:o:", long_opts, while ((cmd_opt = getopt_long(argc, argv, "vhxc:f:d:a:k:s:o:", long_opts,
NULL)) != -1) { NULL)) != -1) {
switch (cmd_opt) { switch (cmd_opt) {
case 0: case 0:
...@@ -107,8 +113,12 @@ int main(int argc, char *argv[]) ...@@ -107,8 +113,12 @@ int main(int argc, char *argv[])
/* RAM address on the AXI bus in bytes */ /* RAM address on the AXI bus in bytes */
address = getopt_integer(optarg); address = getopt_integer(optarg);
break; break;
/* RAM size in bytes */ case 'k':
/* memory aperture windows size */
aperture = getopt_integer(optarg);
break;
case 's': case 's':
/* RAM size in bytes */
size = getopt_integer(optarg); size = getopt_integer(optarg);
break; break;
case 'o': case 'o':
...@@ -138,17 +148,20 @@ int main(int argc, char *argv[]) ...@@ -138,17 +148,20 @@ int main(int argc, char *argv[])
} }
if (verbose) if (verbose)
fprintf(stdout, fprintf(stdout,
"dev %s, addr 0x%lx, size 0x%lx, offset 0x%lx, count %lu\n", "dev %s, addr 0x%lx, aperture 0x%lx, size 0x%lx, offset 0x%lx, "
device, address, size, offset, count); "count %lu\n",
device, address, aperture, size, offset, count);
return test_dma(device, address, size, offset, count, ofname); return test_dma(device, address, aperture, size, offset, count, ofname);
} }
static int test_dma(char *devname, uint64_t addr, uint64_t size, static int test_dma(char *devname, uint64_t addr, uint64_t aperture,
uint64_t offset, uint64_t count, char *ofname) uint64_t size, uint64_t offset, uint64_t count,
char *ofname)
{ {
ssize_t rc; ssize_t rc;
uint64_t i; uint64_t i;
uint64_t apt_loop = aperture ? (size + aperture - 1) / aperture : 0;
char *buffer = NULL; char *buffer = NULL;
char *allocated = NULL; char *allocated = NULL;
struct timespec ts_start, ts_end; struct timespec ts_start, ts_end;
...@@ -191,10 +204,25 @@ static int test_dma(char *devname, uint64_t addr, uint64_t size, ...@@ -191,10 +204,25 @@ static int test_dma(char *devname, uint64_t addr, uint64_t size,
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
rc = clock_gettime(CLOCK_MONOTONIC, &ts_start); rc = clock_gettime(CLOCK_MONOTONIC, &ts_start);
/* lseek & read data from AXI MM into buffer using SGDMA */ if (apt_loop) {
rc = read_to_buffer(devname, fpga_fd, buffer, size, addr); uint64_t j;
if (rc < 0) uint64_t len = size;
goto out; char *buf = buffer;
for (j = 0; j < apt_loop; j++, len -= aperture, buf += aperture) {
/* lseek & read data from AXI MM into buffer using SGDMA */
rc = read_to_buffer(devname, fpga_fd, buf,
(len > aperture) ? aperture : len,
addr);
if (rc < 0)
goto out;
}
} else {
/* lseek & read data from AXI MM into buffer using SGDMA */
rc = read_to_buffer(devname, fpga_fd, buffer, size, addr);
if (rc < 0)
goto out;
}
clock_gettime(CLOCK_MONOTONIC, &ts_end); clock_gettime(CLOCK_MONOTONIC, &ts_end);
/* subtract the start time from the end time */ /* subtract the start time from the end time */
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
static struct option const long_opts[] = { static struct option const long_opts[] = {
{"device", required_argument, NULL, 'd'}, {"device", required_argument, NULL, 'd'},
{"address", required_argument, NULL, 'a'}, {"address", required_argument, NULL, 'a'},
{"aperture", required_argument, NULL, 'k'},
{"size", required_argument, NULL, 's'}, {"size", required_argument, NULL, 's'},
{"offset", required_argument, NULL, 'o'}, {"offset", required_argument, NULL, 'o'},
{"count", required_argument, NULL, 'c'}, {"count", required_argument, NULL, 'c'},
...@@ -47,8 +48,9 @@ static struct option const long_opts[] = { ...@@ -47,8 +48,9 @@ static struct option const long_opts[] = {
#define COUNT_DEFAULT (1) #define COUNT_DEFAULT (1)
static int test_dma(char *devname, uint64_t addr, uint64_t size, static int test_dma(char *devname, uint64_t addr, uint64_t aperture,
uint64_t offset, uint64_t count, char *filename, char *); uint64_t size, uint64_t offset, uint64_t count,
char *filename, char *);
static void usage(const char *name) static void usage(const char *name)
{ {
...@@ -65,6 +67,9 @@ static void usage(const char *name) ...@@ -65,6 +67,9 @@ static void usage(const char *name)
fprintf(stdout, " -%c (--%s) the start address on the AXI bus\n", fprintf(stdout, " -%c (--%s) the start address on the AXI bus\n",
long_opts[i].val, long_opts[i].name); long_opts[i].val, long_opts[i].name);
i++; i++;
fprintf(stdout, " -%c (--%s) memory address aperture\n",
long_opts[i].val, long_opts[i].name);
i++;
fprintf(stdout, fprintf(stdout,
" -%c (--%s) size of a single transfer in bytes, default %d,\n", " -%c (--%s) size of a single transfer in bytes, default %d,\n",
long_opts[i].val, long_opts[i].name, SIZE_DEFAULT); long_opts[i].val, long_opts[i].name, SIZE_DEFAULT);
...@@ -95,6 +100,7 @@ int main(int argc, char *argv[]) ...@@ -95,6 +100,7 @@ int main(int argc, char *argv[])
int cmd_opt; int cmd_opt;
char *device = DEVICE_NAME_DEFAULT; char *device = DEVICE_NAME_DEFAULT;
uint64_t address = 0; uint64_t address = 0;
uint64_t aperture = 0;
uint64_t size = SIZE_DEFAULT; uint64_t size = SIZE_DEFAULT;
uint64_t offset = 0; uint64_t offset = 0;
uint64_t count = COUNT_DEFAULT; uint64_t count = COUNT_DEFAULT;
...@@ -102,7 +108,7 @@ int main(int argc, char *argv[]) ...@@ -102,7 +108,7 @@ int main(int argc, char *argv[])
char *ofname = NULL; char *ofname = NULL;
while ((cmd_opt = while ((cmd_opt =
getopt_long(argc, argv, "vhc:f:d:a:s:o:w:", long_opts, getopt_long(argc, argv, "vhc:f:d:a:k:s:o:w:", long_opts,
NULL)) != -1) { NULL)) != -1) {
switch (cmd_opt) { switch (cmd_opt) {
case 0: case 0:
...@@ -117,6 +123,10 @@ int main(int argc, char *argv[]) ...@@ -117,6 +123,10 @@ int main(int argc, char *argv[])
/* RAM address on the AXI bus in bytes */ /* RAM address on the AXI bus in bytes */
address = getopt_integer(optarg); address = getopt_integer(optarg);
break; break;
case 'k':
/* memory aperture windows size */
aperture = getopt_integer(optarg);
break;
case 's': case 's':
/* size in bytes */ /* size in bytes */
size = getopt_integer(optarg); size = getopt_integer(optarg);
...@@ -149,18 +159,21 @@ int main(int argc, char *argv[]) ...@@ -149,18 +159,21 @@ int main(int argc, char *argv[])
if (verbose) if (verbose)
fprintf(stdout, fprintf(stdout,
"dev %s, address 0x%lx, size 0x%lx, offset 0x%lx, count %lu\n", "dev %s, addr 0x%lx, aperture 0x%lx, size 0x%lx, offset 0x%lx, "
device, address, size, offset, count); "count %lu\n",
device, address, aperture, size, offset, count);
return test_dma(device, address, size, offset, count, infname, ofname); return test_dma(device, address, aperture, size, offset, count,
infname, ofname);
} }
static int test_dma(char *devname, uint64_t addr, uint64_t size, static int test_dma(char *devname, uint64_t addr, uint64_t aperture,
uint64_t offset, uint64_t count, char *infname, uint64_t size, uint64_t offset, uint64_t count,
char *ofname) char *infname, char *ofname)
{ {
uint64_t i; uint64_t i;
ssize_t rc; ssize_t rc;
uint64_t apt_loop = aperture ? (size + aperture - 1) / aperture : 0;
char *buffer = NULL; char *buffer = NULL;
char *allocated = NULL; char *allocated = NULL;
struct timespec ts_start, ts_end; struct timespec ts_start, ts_end;
...@@ -223,9 +236,25 @@ static int test_dma(char *devname, uint64_t addr, uint64_t size, ...@@ -223,9 +236,25 @@ static int test_dma(char *devname, uint64_t addr, uint64_t size,
/* write buffer to AXI MM address using SGDMA */ /* write buffer to AXI MM address using SGDMA */
rc = clock_gettime(CLOCK_MONOTONIC, &ts_start); rc = clock_gettime(CLOCK_MONOTONIC, &ts_start);
rc = write_from_buffer(devname, fpga_fd, buffer, size, addr); if (apt_loop) {
if (rc < 0) uint64_t j;
goto out; uint64_t len = size;
char *buf = buffer;
for (j = 0; j < apt_loop; j++, len -= aperture,
buf += aperture) {
rc = write_from_buffer(devname, fpga_fd, buf,
(len > aperture) ? aperture : len,
addr);
if (rc < 0)
goto out;
}
} else {
rc = write_from_buffer(devname, fpga_fd, buffer, size,
addr);
if (rc < 0)
goto out;
}
rc = clock_gettime(CLOCK_MONOTONIC, &ts_end); rc = clock_gettime(CLOCK_MONOTONIC, &ts_end);
/* subtract the start time from the end time */ /* subtract the start time from the end time */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment