diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2015-05-05 15:27:22 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2015-05-05 15:27:22 +0200 |
commit | 890ba303b28be816ff00f464b6f3a6b000b5e6e2 (patch) | |
tree | df4c72a5f1f72d37cba07b490e189d6da9b75e3e /pcilib/fifo.c | |
parent | 0ccd08c98b5d41927099a552dad379221e63cd89 (diff) | |
download | pcitool-890ba303b28be816ff00f464b6f3a6b000b5e6e2.tar.gz pcitool-890ba303b28be816ff00f464b6f3a6b000b5e6e2.tar.bz2 pcitool-890ba303b28be816ff00f464b6f3a6b000b5e6e2.tar.xz pcitool-890ba303b28be816ff00f464b6f3a6b000b5e6e2.zip |
Split bar manipulation and fifo operations in stand-alone source and publish kmem and bar headers
Diffstat (limited to 'pcilib/fifo.c')
-rw-r--r-- | pcilib/fifo.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/pcilib/fifo.c b/pcilib/fifo.c new file mode 100644 index 0000000..593400f --- /dev/null +++ b/pcilib/fifo.c @@ -0,0 +1,55 @@ +#define _BSD_SOURCE +#define _POSIX_C_SOURCE 200809L + +#include <stdio.h> +#include <string.h> +#include <strings.h> +#include <stdlib.h> +#include <stdint.h> +#include <fcntl.h> +#include <unistd.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <arpa/inet.h> +#include <errno.h> +#include <assert.h> + +#include "pcilib.h" +#include "pci.h" +#include "tools.h" +#include "error.h" +#include "model.h" +#include "plugin.h" +#include "bar.h" + +int pcilib_read_fifo(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr, uint8_t fifo_size, size_t n, void *buf) { + int i; + void *data; + + pcilib_detect_address(ctx, &bar, &addr, fifo_size); + data = pcilib_map_bar(ctx, bar); + + for (i = 0; i < n; i++) { + pcilib_memcpy(buf + i * fifo_size, data + addr, fifo_size); + } + + pcilib_unmap_bar(ctx, bar, data); + + return 0; +} + +int pcilib_write_fifo(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr, uint8_t fifo_size, size_t n, void *buf) { + int i; + void *data; + + pcilib_detect_address(ctx, &bar, &addr, fifo_size); + data = pcilib_map_bar(ctx, bar); + + for (i = 0; i < n; i++) { + pcilib_memcpy(data + addr, buf + i * fifo_size, fifo_size); + } + + pcilib_unmap_bar(ctx, bar, data); + + return 0; +} |