minix/servers/vm/mem_directphys.c
Ben Gras 49eb1f4806 vm: new secondary cache code
Primary purpose of change: to support the mmap implementation, VM must
know both (a) about some block metadata for FS cache blocks, i.e.
inode numbers and inode offsets where applicable; and (b) know about
*all* cache blocks, i.e.  also of the FS primary caches and not just
the blocks that spill into the secondary one. This changes the
interface and VM data structures.

This change is only for the interface (libminixfs) and VM data
structures; the filesystem code is unmodified, so although the
secondary cache will be used as normal, blocks will not be annotated
with inode information until the FS is modified to provide this
information. Until it is modified, mmap of files will fail gracefully
on such filesystems.

This is indicated to VFS/VM by returning ENOSYS for REQ_PEEK.

Change-Id: I1d2df6c485e6c5e89eb28d9055076cc02629594e
2013-04-24 10:18:16 +00:00

64 lines
1.7 KiB
C

/* This file implements the methods of direct physical mapping.
*
* A direct physical mapping is done by accepting the physical
* memory address and range from the caller and allowing direct
* access to it. Most significantly, no physical memory is allocated
* when it's mapped or freed when it's unmapped. E.g. device memory.
*/
#include "vm.h"
/* These functions are static so as to not pollute the
* global namespace, and are accessed through their function
* pointers.
*/
static int phys_unreference(struct phys_region *pr);
static int phys_writable(struct phys_region *pr);
static int phys_pagefault(struct vmproc *vmp, struct vir_region *region,
struct phys_region *ph, int write, vfs_callback_t cb, void *, int);
static int phys_copy(struct vir_region *vr, struct vir_region *newvr);
struct mem_type mem_type_directphys = {
.name = "physical memory mapping",
.ev_copy = phys_copy,
.ev_unreference = phys_unreference,
.writable = phys_writable,
.ev_pagefault = phys_pagefault
};
static int phys_unreference(struct phys_region *pr)
{
return OK;
}
static int phys_pagefault(struct vmproc *vmp, struct vir_region *region,
struct phys_region *ph, int write, vfs_callback_t cb, void *st, int len)
{
phys_bytes arg = region->param.phys, phmem;
assert(arg != MAP_NONE);
assert(ph->ph->phys == MAP_NONE);
phmem = arg + ph->offset;
assert(phmem != MAP_NONE);
ph->ph->phys = phmem;
return OK;
}
static int phys_writable(struct phys_region *pr)
{
assert(pr->ph->refcount > 0);
return pr->ph->phys != MAP_NONE;
}
void phys_setphys(struct vir_region *vr, phys_bytes phys)
{
vr->param.phys = phys;
}
static int phys_copy(struct vir_region *vr, struct vir_region *newvr)
{
newvr->param.phys = vr->param.phys;
return OK;
}