diff options
author | zilio nicolas <nicolas.zilio@kit.edu> | 2015-08-26 14:45:18 +0200 |
---|---|---|
committer | zilio nicolas <nicolas.zilio@kit.edu> | 2015-08-26 14:45:18 +0200 |
commit | 1e5f0b6d5e02c0dc11bedefa92fc3c5bb406845a (patch) | |
tree | a978bd11f64f619ee8f40e42e73a582754c122de /pcilib/bar.c | |
parent | 0f298bd861ac8d847f33d6b8bc73b089d2749bbb (diff) | |
parent | 6bad94bb8546a3a5595d340e7a2d809635e3bd5d (diff) | |
download | pcitool-1e5f0b6d5e02c0dc11bedefa92fc3c5bb406845a.tar.gz pcitool-1e5f0b6d5e02c0dc11bedefa92fc3c5bb406845a.tar.bz2 pcitool-1e5f0b6d5e02c0dc11bedefa92fc3c5bb406845a.tar.xz pcitool-1e5f0b6d5e02c0dc11bedefa92fc3c5bb406845a.zip |
pull from server
Diffstat (limited to 'pcilib/bar.c')
-rw-r--r-- | pcilib/bar.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/pcilib/bar.c b/pcilib/bar.c index 2c7a8d4..2666506 100644 --- a/pcilib/bar.c +++ b/pcilib/bar.c @@ -73,21 +73,29 @@ int pcilib_detect_address(pcilib_t *ctx, pcilib_bar_t *bar, uintptr_t *addr, siz void *pcilib_map_bar(pcilib_t *ctx, pcilib_bar_t bar) { void *res; - int ret; + int err, ret; const pcilib_board_info_t *board_info = pcilib_get_board_info(ctx); if (!board_info) return NULL; - + if (ctx->bar_space[bar]) return ctx->bar_space[bar]; - + + err = pcilib_lock_global(ctx); + if (err) { + pcilib_error("Error (%i) acquiring mmap lock", err); + return NULL; + } + ret = ioctl( ctx->handle, PCIDRIVER_IOC_MMAP_MODE, PCIDRIVER_MMAP_PCI ); if (ret) { + pcilib_unlock_global(ctx); pcilib_error("PCIDRIVER_IOC_MMAP_MODE ioctl have failed", bar); return NULL; } ret = ioctl( ctx->handle, PCIDRIVER_IOC_MMAP_AREA, PCIDRIVER_BAR0 + bar ); if (ret) { + pcilib_unlock_global(ctx); pcilib_error("PCIDRIVER_IOC_MMAP_AREA ioctl have failed for bank %i", bar); return NULL; } @@ -98,12 +106,14 @@ void *pcilib_map_bar(pcilib_t *ctx, pcilib_bar_t bar) { #else res = mmap( 0, board_info->bar_length[bar], PROT_WRITE | PROT_READ, MAP_SHARED, ctx->handle, 0 ); #endif + + pcilib_unlock_global(ctx); + if ((!res)||(res == MAP_FAILED)) { pcilib_error("Failed to mmap data bank %i", bar); return NULL; } - return res; } |