index aa2a6fc61bdb50eb31065b957778ae9eb8f40f78..05031c810d4a22505dbdf52e219d396a43bee14b 100644 (file)
#include "mpm_transport_edma3.h"
#include "mpm_transport_time_profile.h"
-uint32_t edma3_mmap(uint32_t addr, uint32_t size, int fd)
+#include "uio_module_drv.h"
+
+uint32_t edma3_mmap(uint32_t addr, uint32_t offset, uint32_t size, int fd)
{
uint32_t virt_addr;
- uint32_t page_size, mapaddr, offset;
+ uint32_t page_size, pg_offset, base_correction, mmap_length;
+
page_size = getpagesize();
- mapaddr = addr & (~(page_size - 1));
- offset = addr - mapaddr;
- virt_addr = (uint32_t) mmap(0, size + offset, (PROT_READ|PROT_WRITE), MAP_SHARED, fd, (off_t)mapaddr);
+ base_correction = addr & (page_size -1);
+ pg_offset = offset & (~((page_size<< UIO_MODULE_DRV_MAP_OFFSET_SHIFT) - 1));
+ mmap_length = size + offset - pg_offset + base_correction;
+
+
+ /* Map with index 0 */
+ virt_addr = (uint32_t) mmap(NULL, mmap_length, (PROT_READ|PROT_WRITE), MAP_SHARED, fd,
+ pg_offset);
if (virt_addr == -1)
{
mpm_printf(1, "EDMA3 mmap failed for address 0x%08x, size 0x%08x!\n",addr,size);
return 0;
}
- return virt_addr + offset;
+ return virt_addr + (offset - pg_offset) + base_correction;
}
int setupEdmaConfig(EDMA3_DRV_GblConfigParams *cfg)
{
int i;
int edma_fd;
+ uint32_t mmap_base_dma_addr;
+
if((edma_fd = open("/dev/edma3", (O_RDWR))) == -1)
{
mpm_printf(1, "Failed to open \"dev/edma3\" err=%s\n",
strerror(errno));
return -1;
}
- cfg->globalRegs = (uint32_t *)edma3_mmap((uint32_t)cfg->globalRegs, 0x8000, edma_fd);
+ mmap_base_dma_addr = (uint32_t)cfg->globalRegs;
+ cfg->globalRegs = (uint32_t *)edma3_mmap(mmap_base_dma_addr, 0, 0x8000, edma_fd);
if (cfg->globalRegs == 0) {
if (edma_fd) close(edma_fd);
return -1;
{
if (cfg->tcRegs[i] != NULL)
{
- cfg->tcRegs[i] =(uint32_t *)edma3_mmap((uint32_t)cfg->tcRegs[i], 0x1000, edma_fd);
+ cfg->tcRegs[i] =(uint32_t *)edma3_mmap((uint32_t)cfg->tcRegs[i],
+ ((uint32_t)cfg->tcRegs[i] - mmap_base_dma_addr),
+ 0x1000, edma_fd);
if (cfg->tcRegs[i] == 0) {
if (edma_fd) close(edma_fd);
return -1;