| 1 |
/* Memory manager interface */ |
| 2 |
#include <stdio.h> |
| 3 |
#include <sys/ioctl.h> |
| 4 |
#include <sys/mman.h> /* mlock */ |
| 5 |
#include <errno.h> |
| 6 |
#include <unistd.h> |
| 7 |
#include <fcntl.h> |
| 8 |
#include "libdha.h" |
| 9 |
#include "kernelhelper/dhahelper.h" |
| 10 |
|
| 11 |
static int libdha_fd=-1; |
| 12 |
|
| 13 |
#define ALLOWED_VER 0x10 |
| 14 |
int bm_open( void ) |
| 15 |
{ |
| 16 |
int retv; |
| 17 |
libdha_fd = open("/dev/dhahelper",O_RDWR); |
| 18 |
retv = libdha_fd > 0 ? 0 : ENXIO; |
| 19 |
if(!retv) |
| 20 |
{ |
| 21 |
int ver; |
| 22 |
ioctl(libdha_fd,DHAHELPER_GET_VERSION,&ver); |
| 23 |
if(ver < ALLOWED_VER) |
| 24 |
{ |
| 25 |
printf("libdha: You have wrong version (%i) of /dev/dhahelper\n" |
| 26 |
"libdha: Please upgrade your driver up to ver=%i\n",ver,ALLOWED_VER); |
| 27 |
retv = EINVAL; |
| 28 |
close(libdha_fd); |
| 29 |
} |
| 30 |
} |
| 31 |
else printf("libdha: Can't open /dev/dhahelper\n"); |
| 32 |
return retv; |
| 33 |
} |
| 34 |
|
| 35 |
void bm_close( void ) |
| 36 |
{ |
| 37 |
close(libdha_fd); |
| 38 |
} |
| 39 |
|
| 40 |
int bm_virt_to_phys( void * virt_addr, unsigned long length, unsigned long * parray ) |
| 41 |
{ |
| 42 |
dhahelper_vmi_t vmi; |
| 43 |
vmi.virtaddr = virt_addr; |
| 44 |
vmi.length = length; |
| 45 |
vmi.realaddr = parray; |
| 46 |
if(libdha_fd > 0) return ioctl(libdha_fd,DHAHELPER_VIRT_TO_PHYS,&vmi); |
| 47 |
return ENXIO; |
| 48 |
} |
| 49 |
|
| 50 |
int bm_virt_to_bus( void * virt_addr, unsigned long length, unsigned long * barray ) |
| 51 |
{ |
| 52 |
dhahelper_vmi_t vmi; |
| 53 |
vmi.virtaddr = virt_addr; |
| 54 |
vmi.length = length; |
| 55 |
vmi.realaddr = barray; |
| 56 |
if(libdha_fd > 0) return ioctl(libdha_fd,DHAHELPER_VIRT_TO_BUS,&vmi); |
| 57 |
return ENXIO; |
| 58 |
} |
| 59 |
|
| 60 |
void * bm_alloc_pci_shmem(pciinfo_t *pi, unsigned mem_bitness, unsigned long length,int op ) |
| 61 |
{ |
| 62 |
printf("libdha: Pure virtual function call - bm_alloc_pci_shmem()\n"); |
| 63 |
#if 0 |
| 64 |
dhahelper_mem_t vmi; |
| 65 |
vmi.length = length; |
| 66 |
if(libdha_fd > 0) |
| 67 |
{ |
| 68 |
if(ioctl(libdha_fd,DHAHELPER_ALLOC_PA,&vmi) == 0) |
| 69 |
return vmi.addr; |
| 70 |
} |
| 71 |
#endif |
| 72 |
return 0; |
| 73 |
} |
| 74 |
|
| 75 |
void bm_free_pci_shmem(void * pci_shmem) |
| 76 |
{ |
| 77 |
printf("libdha: Pure virtual function call - bm_free_pci_shmem()\n"); |
| 78 |
#if 0 |
| 79 |
dhahelper_mem_t vmi; |
| 80 |
vmi.addr = virt_addr; |
| 81 |
vmi.length = length; |
| 82 |
if(libdha_fd > 0) |
| 83 |
{ |
| 84 |
ioctl(libdha_fd,DHAHELPER_FREE_PA,&vmi); |
| 85 |
} |
| 86 |
#endif |
| 87 |
} |
| 88 |
|
| 89 |
int bm_lock_mem( const void *addr, unsigned long length ) |
| 90 |
{ |
| 91 |
dhahelper_mem_t vmi; |
| 92 |
vmi.addr = addr; |
| 93 |
vmi.length = length; |
| 94 |
if(libdha_fd > 0) |
| 95 |
{ |
| 96 |
return ioctl(libdha_fd,DHAHELPER_LOCK_MEM,&vmi); |
| 97 |
} |
| 98 |
return mlock(addr,length); |
| 99 |
} |
| 100 |
|
| 101 |
int bm_unlock_mem( const void * addr, unsigned long length ) |
| 102 |
{ |
| 103 |
dhahelper_mem_t vmi; |
| 104 |
vmi.addr = addr; |
| 105 |
vmi.length = length; |
| 106 |
if(libdha_fd > 0) |
| 107 |
{ |
| 108 |
return ioctl(libdha_fd,DHAHELPER_UNLOCK_MEM,&vmi); |
| 109 |
} |
| 110 |
return munlock(addr,length); |
| 111 |
} |