diff options
author | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2011-12-14 00:29:21 +0100 |
---|---|---|
committer | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2011-12-14 00:29:21 +0100 |
commit | c4c9ad7708ddd3114f78c5f860ebfeb92cfb79c3 (patch) | |
tree | 19063034154415a9a0076b18d7b626dad50bc2ea | |
parent | a7cd579fbd12fdfc84ac5eff32dd5af093d78631 (diff) | |
download | ipecamera-c4c9ad7708ddd3114f78c5f860ebfeb92cfb79c3.tar.gz ipecamera-c4c9ad7708ddd3114f78c5f860ebfeb92cfb79c3.tar.bz2 ipecamera-c4c9ad7708ddd3114f78c5f860ebfeb92cfb79c3.tar.xz ipecamera-c4c9ad7708ddd3114f78c5f860ebfeb92cfb79c3.zip |
Synchronize kernel buffers during the read-kernel-memory and while accessing via sysfs
-rw-r--r-- | cli.c | 19 | ||||
-rw-r--r-- | driver/kmem.c | 29 | ||||
-rw-r--r-- | driver/kmem.h | 1 | ||||
-rw-r--r-- | driver/sysfs.c | 5 | ||||
-rw-r--r-- | kmem.c | 10 | ||||
-rw-r--r-- | kmem.h | 2 |
6 files changed, 40 insertions, 26 deletions
@@ -1836,13 +1836,21 @@ int ListKMEM(pcilib_t *handle, const char *device) { } int ReadKMEM(pcilib_t *handle, const char *device, pcilib_kmem_use_t use, size_t block, size_t max_size, FILE *o) { + int err; void *data; size_t size; pcilib_kmem_handle_t *kbuf; kbuf = pcilib_alloc_kernel_memory(handle, 0, block + 1, 0, 0, use, PCILIB_KMEM_FLAG_REUSE|PCILIB_KMEM_FLAG_TRY); if (!kbuf) { - printf("The specified kernel buffer is not allocated\n"); + Error("The specified kernel buffer is not allocated\n"); + return 0; + } + + err = pcilib_kmem_sync_block(handle, kbuf, PCILIB_KMEM_SYNC_FROMDEVICE, block); + if (err) { + pcilib_free_kernel_memory(handle, kbuf, KMEM_FLAG_REUSE); + Error("The synchronization of kernel buffer has failed\n"); return 0; } @@ -1850,9 +1858,12 @@ int ReadKMEM(pcilib_t *handle, const char *device, pcilib_kmem_use_t use, size_t if (data) { size = pcilib_kmem_get_block_size(handle, kbuf, block); if ((max_size)&&(size > max_size)) size = max_size; + fwrite(data, 1, size, o?o:stdout); } else { - printf("The specified block is not existing\n"); + pcilib_free_kernel_memory(handle, kbuf, KMEM_FLAG_REUSE); + Error("The specified block is not existing\n"); + return 0; } pcilib_free_kernel_memory(handle, kbuf, KMEM_FLAG_REUSE); @@ -2069,10 +2080,6 @@ int ReadBuffer(pcilib_t *handle, const char *device, pcilib_model_description_t pcilib_stop_dma(handle, dmaid, 0); - - -// printf("%i %i\n", dma, buffer); -// printf("%lx\n", ((dma&0x7F)|((dma_direction == PCILIB_DMA_TO_DEVICE)?0x80:0x00))|(PCILIB_KMEM_USE_DMA_PAGES<<16)); return ReadKMEM(handle, device, ((dma&0x7F)|((dma_direction == PCILIB_DMA_TO_DEVICE)?0x80:0x00))|(PCILIB_KMEM_USE_DMA_PAGES<<16), block, size, o); } diff --git a/driver/kmem.c b/driver/kmem.c index acf1263..37a7368 100644 --- a/driver/kmem.c +++ b/driver/kmem.c @@ -323,24 +323,19 @@ int pcidriver_kmem_free_all(pcidriver_privdata_t *privdata) return 0; } + /** * * Synchronize memory to/from the device (or in both directions). * */ -int pcidriver_kmem_sync( pcidriver_privdata_t *privdata, kmem_sync_t *kmem_sync ) +int pcidriver_kmem_sync_entry( pcidriver_privdata_t *privdata, pcidriver_kmem_entry_t *kmem_entry, int direction) { - pcidriver_kmem_entry_t *kmem_entry; - - /* Find the associated kmem_entry for this buffer */ - if ((kmem_entry = pcidriver_kmem_find_entry(privdata, &(kmem_sync->handle))) == NULL) - return -EINVAL; /* kmem_handle is not valid */ - if (kmem_entry->direction == PCI_DMA_NONE) return -EINVAL; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11) - switch (kmem_sync->dir) { + switch (direction) { case PCILIB_KMEM_SYNC_TODEVICE: pci_dma_sync_single_for_device( privdata->pdev, kmem_entry->dma_handle, kmem_entry->size, kmem_entry->direction ); break; @@ -355,7 +350,7 @@ int pcidriver_kmem_sync( pcidriver_privdata_t *privdata, kmem_sync_t *kmem_sync return -EINVAL; /* wrong direction parameter */ } #else - switch (kmem_sync->dir) { + switch (direction) { case PCILIB_KMEM_SYNC_TODEVICE: pci_dma_sync_single( privdata->pdev, kmem_entry->dma_handle, kmem_entry->size, kmem_entry->direction ); break; @@ -375,6 +370,22 @@ int pcidriver_kmem_sync( pcidriver_privdata_t *privdata, kmem_sync_t *kmem_sync /** * + * Synchronize memory to/from the device (or in both directions). + * + */ +int pcidriver_kmem_sync( pcidriver_privdata_t *privdata, kmem_sync_t *kmem_sync ) +{ + pcidriver_kmem_entry_t *kmem_entry; + + /* Find the associated kmem_entry for this buffer */ + if ((kmem_entry = pcidriver_kmem_find_entry(privdata, &(kmem_sync->handle))) == NULL) + return -EINVAL; /* kmem_handle is not valid */ + + return pcidriver_kmem_sync_entry(privdata, kmem_entry, kmem_sync->dir); +} + +/** + * * Free the given kmem_entry and its memory. * */ diff --git a/driver/kmem.h b/driver/kmem.h index ee12855..503620e 100644 --- a/driver/kmem.h +++ b/driver/kmem.h @@ -1,5 +1,6 @@ int pcidriver_kmem_alloc( pcidriver_privdata_t *privdata, kmem_handle_t *kmem_handle ); int pcidriver_kmem_free( pcidriver_privdata_t *privdata, kmem_handle_t *kmem_handle ); +int pcidriver_kmem_sync_entry( pcidriver_privdata_t *privdata, pcidriver_kmem_entry_t *kmem_entry, int direction ); int pcidriver_kmem_sync( pcidriver_privdata_t *privdata, kmem_sync_t *kmem_sync ); int pcidriver_kmem_free_all( pcidriver_privdata_t *privdata ); pcidriver_kmem_entry_t *pcidriver_kmem_find_entry( pcidriver_privdata_t *privdata, kmem_handle_t *kmem_handle ); diff --git a/driver/sysfs.c b/driver/sysfs.c index be6f7d9..37cf362 100644 --- a/driver/sysfs.c +++ b/driver/sysfs.c @@ -101,9 +101,10 @@ static SYSFS_GET_FUNCTION(pcidriver_show_kmem_entry) int id = simple_strtol(attr->attr.name + strlen("kbuf"), NULL, 10); pcidriver_kmem_entry_t *entry = pcidriver_kmem_find_entry_id(privdata, id); if (entry) - if (entry->size >= 16) + if (entry->size >= 16) { + pcidriver_kmem_sync_entry(privdata, entry, PCILIB_KMEM_SYNC_FROMDEVICE); return snprintf(buf, PAGE_SIZE, "buffer: %d\ntype: %lx\nuse: 0x%lx\nitem: %lu\nsize: %lu\nrefs: %lu\nhw ref: %i\nmode: 0x%lx\ndata: %8x %8x %8x %8x\n", id, entry->type, entry->use, entry->item, entry->size, entry->refs&KMEM_REF_COUNT, (entry->refs&KMEM_REF_HW)?1:0, entry->mode, *(u32*)(entry->cpua), *(u32*)(entry->cpua + 4), *(u32*)(entry->cpua + 8), *(u32*)(entry->cpua + 12)); - else + } else return snprintf(buf, PAGE_SIZE, "buffer: %d\ntype: %lx\nuse: 0x%lx\nitem: %lu\nsize: %lu\nrefs: %lu\nhw ref: %i\nmode: 0x%lx\n", id, entry->type, entry->use, entry->item, entry->size, entry->refs&KMEM_REF_COUNT, (entry->refs&KMEM_REF_HW)?1:0, entry->mode); else return snprintf(buf, PAGE_SIZE, "I am in the kmem_entry show function for buffer %d\n", id); @@ -229,18 +229,13 @@ void pcilib_free_kernel_memory(pcilib_t *ctx, pcilib_kmem_handle_t *k, pcilib_km } /* -int pcilib_sync_kernel_memory(pcilib_t *ctx, pcilib_kmem_handle_t *k, pcilib_kmem_sync_direction_t dir) { +int pcilib_kmem_sync(pcilib_t *ctx, pcilib_kmem_handle_t *k, pcilib_kmem_sync_direction_t dir) { int i; int ret; - kmem_sync_t ks; pcilib_kmem_list_t *kbuf = (pcilib_kmem_list_t*)k; - ks.dir = dir; - for (i = 0; i < kbuf->buf.n_blocks; i++) { - ks.handle.handle_id = kbuf->buf.blocks[i].handle_id; - ks.handle.pa = kbuf->buf.blocks[i].pa; - ret = ioctl(ctx->handle, PCIDRIVER_IOC_KMEM_SYNC, &ks); + ret = pcilib_kmem_sync_block(ctx, k, dir, i); if (ret) { pcilib_error("PCIDRIVER_IOC_KMEM_SYNC ioctl have failed"); return PCILIB_ERROR_FAILED; @@ -249,7 +244,6 @@ int pcilib_sync_kernel_memory(pcilib_t *ctx, pcilib_kmem_handle_t *k, pcilib_kme return 0; } - */ int pcilib_kmem_sync_block(pcilib_t *ctx, pcilib_kmem_handle_t *k, pcilib_kmem_sync_direction_t dir, size_t block) { @@ -62,7 +62,7 @@ struct pcilib_kmem_list_s { pcilib_kmem_handle_t *pcilib_alloc_kernel_memory(pcilib_t *ctx, pcilib_kmem_type_t type, size_t nmemb, size_t size, size_t alignment, pcilib_kmem_use_t use, pcilib_kmem_flags_t flags); void pcilib_free_kernel_memory(pcilib_t *ctx, pcilib_kmem_handle_t *k, pcilib_kmem_flags_t flags); -//int pcilib_sync_kernel_memory(pcilib_t *ctx, pcilib_kmem_handle_t *k, pcilib_kmem_sync_direction_t dir); +//int pcilib_kmem_sync(pcilib_t *ctx, pcilib_kmem_handle_t *k, pcilib_kmem_sync_direction_t dir); int pcilib_kmem_sync_block(pcilib_t *ctx, pcilib_kmem_handle_t *k, pcilib_kmem_sync_direction_t dir, size_t block); void *pcilib_kmem_get_ua(pcilib_t *ctx, pcilib_kmem_handle_t *k); uintptr_t pcilib_kmem_get_pa(pcilib_t *ctx, pcilib_kmem_handle_t *k); |