From c4c9ad7708ddd3114f78c5f860ebfeb92cfb79c3 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Wed, 14 Dec 2011 00:29:21 +0100 Subject: Synchronize kernel buffers during the read-kernel-memory and while accessing via sysfs --- driver/kmem.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'driver/kmem.c') 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; @@ -373,6 +368,22 @@ int pcidriver_kmem_sync( pcidriver_privdata_t *privdata, kmem_sync_t *kmem_sync return 0; /* success */ } +/** + * + * 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. -- cgit v1.2.3