summaryrefslogtreecommitdiff
path: root/minix/servers/vm/mem_directphys.c
blob: ea4ceb87b1dec8d515c7845f7aaa5ae949a3dc93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

/* 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"
#include "proto.h"
#include "region.h"
#include "glo.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 *state,
	int len, int *io);
static int phys_copy(struct vir_region *vr, struct vir_region *newvr);
static int phys_pt_flags(struct vir_region *vr);

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,
	.pt_flags = phys_pt_flags
};

static int phys_pt_flags(struct vir_region *vr){
#if defined(__arm__)
	return ARM_VM_PTE_DEVICE;
#else
	return 0;
#endif
}

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 *state,
    int len, int *io)
{
	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;
}