xref: /minix3/minix/lib/libsys/vm_cache.c (revision e94f856b38e19c12288b8413a31732118153c230)
1433d6423SLionel Sambuc 
2433d6423SLionel Sambuc #include "syslib.h"
3433d6423SLionel Sambuc 
4433d6423SLionel Sambuc #include <string.h>
5433d6423SLionel Sambuc #include <assert.h>
6433d6423SLionel Sambuc 
7433d6423SLionel Sambuc #include <sys/mman.h>
8433d6423SLionel Sambuc 
9433d6423SLionel Sambuc #include <minix/vm.h>
10433d6423SLionel Sambuc #include <minix/sysutil.h>
11433d6423SLionel Sambuc 
12433d6423SLionel Sambuc #include <machine/param.h>
13433d6423SLionel Sambuc #include <machine/vmparam.h>
14433d6423SLionel Sambuc 
vm_cachecall(message * m,int call,void * addr,dev_t dev,off_t dev_offset,ino_t ino,off_t ino_offset,u32_t * flags,int blocksize,int setflags)15685aa793SDavid van Moolenbroek static int vm_cachecall(message *m, int call, void *addr, dev_t dev,
16685aa793SDavid van Moolenbroek 	off_t dev_offset, ino_t ino, off_t ino_offset, u32_t *flags,
17e321f655SDavid van Moolenbroek 	int blocksize, int setflags)
18433d6423SLionel Sambuc {
19433d6423SLionel Sambuc     if(blocksize % PAGE_SIZE)
20433d6423SLionel Sambuc     	panic("blocksize %d should be a multiple of pagesize %d\n",
21433d6423SLionel Sambuc 		blocksize, PAGE_SIZE);
22433d6423SLionel Sambuc 
23433d6423SLionel Sambuc     if(ino_offset % PAGE_SIZE)
24433d6423SLionel Sambuc     	panic("inode offset %lld should be a multiple of pagesize %d\n",
25433d6423SLionel Sambuc 		ino_offset, PAGE_SIZE);
26433d6423SLionel Sambuc 
27433d6423SLionel Sambuc     if(dev_offset % PAGE_SIZE)
28433d6423SLionel Sambuc     	panic("dev offset offset %lld should be a multiple of pagesize %d\n",
29433d6423SLionel Sambuc 		dev_offset, PAGE_SIZE);
30433d6423SLionel Sambuc 
31433d6423SLionel Sambuc     memset(m, 0, sizeof(*m));
32433d6423SLionel Sambuc 
33433d6423SLionel Sambuc     assert(dev != NO_DEV);
34433d6423SLionel Sambuc 
35433d6423SLionel Sambuc     m->m_vmmcp.dev_offset = dev_offset;
36433d6423SLionel Sambuc     m->m_vmmcp.ino_offset = ino_offset;
37433d6423SLionel Sambuc     m->m_vmmcp.ino = ino;
38433d6423SLionel Sambuc     m->m_vmmcp.block = addr;
39433d6423SLionel Sambuc     m->m_vmmcp.flags_ptr = flags;
40433d6423SLionel Sambuc     m->m_vmmcp.dev = dev;
41433d6423SLionel Sambuc     m->m_vmmcp.pages = blocksize / PAGE_SIZE;
42e321f655SDavid van Moolenbroek     m->m_vmmcp.flags = setflags;
43433d6423SLionel Sambuc 
44433d6423SLionel Sambuc     return _taskcall(VM_PROC_NR, call, m);
45433d6423SLionel Sambuc }
46433d6423SLionel Sambuc 
vm_map_cacheblock(dev_t dev,off_t dev_offset,ino_t ino,off_t ino_offset,u32_t * flags,int blocksize)47433d6423SLionel Sambuc void *vm_map_cacheblock(dev_t dev, off_t dev_offset,
48433d6423SLionel Sambuc 	ino_t ino, off_t ino_offset, u32_t *flags, int blocksize)
49433d6423SLionel Sambuc {
50433d6423SLionel Sambuc 	message m;
51433d6423SLionel Sambuc 
52433d6423SLionel Sambuc 	if(vm_cachecall(&m, VM_MAPCACHEPAGE, NULL, dev, dev_offset,
53e321f655SDavid van Moolenbroek 		ino, ino_offset, flags, blocksize, 0) != OK)
54433d6423SLionel Sambuc 		return MAP_FAILED;
55433d6423SLionel Sambuc 
56433d6423SLionel Sambuc 	return m.m_vmmcp_reply.addr;
57433d6423SLionel Sambuc }
58433d6423SLionel Sambuc 
vm_set_cacheblock(void * block,dev_t dev,off_t dev_offset,ino_t ino,off_t ino_offset,u32_t * flags,int blocksize,int setflags)59433d6423SLionel Sambuc int vm_set_cacheblock(void *block, dev_t dev, off_t dev_offset,
60e321f655SDavid van Moolenbroek 	ino_t ino, off_t ino_offset, u32_t *flags, int blocksize, int setflags)
61433d6423SLionel Sambuc {
62433d6423SLionel Sambuc 	message m;
63433d6423SLionel Sambuc 
64433d6423SLionel Sambuc 	return vm_cachecall(&m, VM_SETCACHEPAGE, block, dev, dev_offset,
65e321f655SDavid van Moolenbroek 		ino, ino_offset, flags, blocksize, setflags);
66433d6423SLionel Sambuc }
67433d6423SLionel Sambuc 
vm_forget_cacheblock(dev_t dev,off_t dev_offset,int blocksize)68*e94f856bSDavid van Moolenbroek int vm_forget_cacheblock(dev_t dev, off_t dev_offset, int blocksize)
69*e94f856bSDavid van Moolenbroek {
70*e94f856bSDavid van Moolenbroek 	message m;
71*e94f856bSDavid van Moolenbroek 
72*e94f856bSDavid van Moolenbroek 	return vm_cachecall(&m, VM_FORGETCACHEPAGE, NULL, dev, dev_offset,
73*e94f856bSDavid van Moolenbroek 		VMC_NO_INODE, 0, 0, blocksize, 0);
74*e94f856bSDavid van Moolenbroek }
75*e94f856bSDavid van Moolenbroek 
76433d6423SLionel Sambuc int
vm_clear_cache(dev_t dev)77433d6423SLionel Sambuc vm_clear_cache(dev_t dev)
78433d6423SLionel Sambuc {
79433d6423SLionel Sambuc 	message m;
80433d6423SLionel Sambuc 
81433d6423SLionel Sambuc 	assert(dev != NO_DEV);
82433d6423SLionel Sambuc 
83433d6423SLionel Sambuc 	memset(&m, 0, sizeof(m));
84433d6423SLionel Sambuc 
85433d6423SLionel Sambuc 	m.m_vmmcp.dev = dev;
86433d6423SLionel Sambuc 
87433d6423SLionel Sambuc 	return _taskcall(VM_PROC_NR, VM_CLEARCACHE, &m);
88433d6423SLionel Sambuc }
89