2012-10-11 15:15:49 +02:00
|
|
|
|
|
|
|
/* 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"
|
2013-08-20 14:02:33 +02:00
|
|
|
#include "proto.h"
|
2013-09-25 10:41:26 +02:00
|
|
|
#include "region.h"
|
|
|
|
#include "glo.h"
|
2012-10-11 15:15:49 +02:00
|
|
|
|
|
|
|
/* 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,
|
2013-06-25 14:41:01 +02:00
|
|
|
struct phys_region *ph, int write, vfs_callback_t cb, void *state,
|
|
|
|
int len, int *io);
|
2012-10-11 15:15:49 +02:00
|
|
|
static int phys_copy(struct vir_region *vr, struct vir_region *newvr);
|
2013-09-25 10:41:26 +02:00
|
|
|
static int phys_pt_flags(struct vir_region *vr);
|
2012-10-11 15:15:49 +02:00
|
|
|
|
|
|
|
struct mem_type mem_type_directphys = {
|
|
|
|
.name = "physical memory mapping",
|
|
|
|
.ev_copy = phys_copy,
|
|
|
|
.ev_unreference = phys_unreference,
|
|
|
|
.writable = phys_writable,
|
2013-09-25 10:41:26 +02:00
|
|
|
.ev_pagefault = phys_pagefault,
|
|
|
|
.pt_flags = phys_pt_flags
|
2012-10-11 15:15:49 +02:00
|
|
|
};
|
|
|
|
|
2013-09-25 10:41:26 +02:00
|
|
|
static int phys_pt_flags(struct vir_region *vr){
|
|
|
|
#if defined(__arm__)
|
|
|
|
return ARM_VM_PTE_DEVICE;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-10-11 15:15:49 +02:00
|
|
|
static int phys_unreference(struct phys_region *pr)
|
|
|
|
{
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int phys_pagefault(struct vmproc *vmp, struct vir_region *region,
|
2013-06-25 14:41:01 +02:00
|
|
|
struct phys_region *ph, int write, vfs_callback_t cb, void *state,
|
|
|
|
int len, int *io)
|
2012-10-11 15:15:49 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|