1 2 #include "syslib.h" 3 4 #include <string.h> 5 #include <assert.h> 6 7 #include <sys/mman.h> 8 9 #include <minix/vm.h> 10 #include <minix/sysutil.h> 11 12 #include <machine/param.h> 13 #include <machine/vmparam.h> 14 15 static int vm_cachecall(message *m, int call, void *addr, dev_t dev, 16 off_t dev_offset, ino_t ino, off_t ino_offset, u32_t *flags, 17 int blocksize, int setflags) 18 { 19 if(blocksize % PAGE_SIZE) 20 panic("blocksize %d should be a multiple of pagesize %d\n", 21 blocksize, PAGE_SIZE); 22 23 if(ino_offset % PAGE_SIZE) 24 panic("inode offset %lld should be a multiple of pagesize %d\n", 25 ino_offset, PAGE_SIZE); 26 27 if(dev_offset % PAGE_SIZE) 28 panic("dev offset offset %lld should be a multiple of pagesize %d\n", 29 dev_offset, PAGE_SIZE); 30 31 memset(m, 0, sizeof(*m)); 32 33 assert(dev != NO_DEV); 34 35 m->m_vmmcp.dev_offset = dev_offset; 36 m->m_vmmcp.ino_offset = ino_offset; 37 m->m_vmmcp.ino = ino; 38 m->m_vmmcp.block = addr; 39 m->m_vmmcp.flags_ptr = flags; 40 m->m_vmmcp.dev = dev; 41 m->m_vmmcp.pages = blocksize / PAGE_SIZE; 42 m->m_vmmcp.flags = setflags; 43 44 return _taskcall(VM_PROC_NR, call, m); 45 } 46 47 void *vm_map_cacheblock(dev_t dev, off_t dev_offset, 48 ino_t ino, off_t ino_offset, u32_t *flags, int blocksize) 49 { 50 message m; 51 52 if(vm_cachecall(&m, VM_MAPCACHEPAGE, NULL, dev, dev_offset, 53 ino, ino_offset, flags, blocksize, 0) != OK) 54 return MAP_FAILED; 55 56 return m.m_vmmcp_reply.addr; 57 } 58 59 int vm_set_cacheblock(void *block, dev_t dev, off_t dev_offset, 60 ino_t ino, off_t ino_offset, u32_t *flags, int blocksize, int setflags) 61 { 62 message m; 63 64 return vm_cachecall(&m, VM_SETCACHEPAGE, block, dev, dev_offset, 65 ino, ino_offset, flags, blocksize, setflags); 66 } 67 68 int vm_forget_cacheblock(dev_t dev, off_t dev_offset, int blocksize) 69 { 70 message m; 71 72 return vm_cachecall(&m, VM_FORGETCACHEPAGE, NULL, dev, dev_offset, 73 VMC_NO_INODE, 0, 0, blocksize, 0); 74 } 75 76 int 77 vm_clear_cache(dev_t dev) 78 { 79 message m; 80 81 assert(dev != NO_DEV); 82 83 memset(&m, 0, sizeof(m)); 84 85 m.m_vmmcp.dev = dev; 86 87 return _taskcall(VM_PROC_NR, VM_CLEARCACHE, &m); 88 } 89