1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#define _BSD_SOURCE
#define _DEFAULT_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, 1);
}
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, 1);
}
pcilib_unmap_bar(ctx, bar, data);
return 0;
}
|