xref: /minix3/minix/servers/vm/mem_directphys.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc 
2*433d6423SLionel Sambuc /* This file implements the methods of direct physical mapping.
3*433d6423SLionel Sambuc  *
4*433d6423SLionel Sambuc  * A direct physical mapping is done by accepting the physical
5*433d6423SLionel Sambuc  * memory address and range from the caller and allowing direct
6*433d6423SLionel Sambuc  * access to it. Most significantly, no physical memory is allocated
7*433d6423SLionel Sambuc  * when it's mapped or freed when it's unmapped. E.g. device memory.
8*433d6423SLionel Sambuc  */
9*433d6423SLionel Sambuc 
10*433d6423SLionel Sambuc #include "vm.h"
11*433d6423SLionel Sambuc #include "proto.h"
12*433d6423SLionel Sambuc #include "region.h"
13*433d6423SLionel Sambuc #include "glo.h"
14*433d6423SLionel Sambuc 
15*433d6423SLionel Sambuc /* These functions are static so as to not pollute the
16*433d6423SLionel Sambuc  * global namespace, and are accessed through their function
17*433d6423SLionel Sambuc  * pointers.
18*433d6423SLionel Sambuc  */
19*433d6423SLionel Sambuc 
20*433d6423SLionel Sambuc static int phys_unreference(struct phys_region *pr);
21*433d6423SLionel Sambuc static int phys_writable(struct phys_region *pr);
22*433d6423SLionel Sambuc static int phys_pagefault(struct vmproc *vmp, struct vir_region *region,
23*433d6423SLionel Sambuc         struct phys_region *ph, int write, vfs_callback_t cb, void *state,
24*433d6423SLionel Sambuc 	int len, int *io);
25*433d6423SLionel Sambuc static int phys_copy(struct vir_region *vr, struct vir_region *newvr);
26*433d6423SLionel Sambuc static int phys_pt_flags(struct vir_region *vr);
27*433d6423SLionel Sambuc 
28*433d6423SLionel Sambuc struct mem_type mem_type_directphys = {
29*433d6423SLionel Sambuc 	.name = "physical memory mapping",
30*433d6423SLionel Sambuc 	.ev_copy = phys_copy,
31*433d6423SLionel Sambuc 	.ev_unreference = phys_unreference,
32*433d6423SLionel Sambuc 	.writable = phys_writable,
33*433d6423SLionel Sambuc 	.ev_pagefault = phys_pagefault,
34*433d6423SLionel Sambuc 	.pt_flags = phys_pt_flags
35*433d6423SLionel Sambuc };
36*433d6423SLionel Sambuc 
phys_pt_flags(struct vir_region * vr)37*433d6423SLionel Sambuc static int phys_pt_flags(struct vir_region *vr){
38*433d6423SLionel Sambuc #if defined(__arm__)
39*433d6423SLionel Sambuc 	return ARM_VM_PTE_DEVICE;
40*433d6423SLionel Sambuc #else
41*433d6423SLionel Sambuc 	return 0;
42*433d6423SLionel Sambuc #endif
43*433d6423SLionel Sambuc }
44*433d6423SLionel Sambuc 
phys_unreference(struct phys_region * pr)45*433d6423SLionel Sambuc static int phys_unreference(struct phys_region *pr)
46*433d6423SLionel Sambuc {
47*433d6423SLionel Sambuc 	return OK;
48*433d6423SLionel Sambuc }
49*433d6423SLionel Sambuc 
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)50*433d6423SLionel Sambuc static int phys_pagefault(struct vmproc *vmp, struct vir_region *region,
51*433d6423SLionel Sambuc     struct phys_region *ph, int write, vfs_callback_t cb, void *state,
52*433d6423SLionel Sambuc     int len, int *io)
53*433d6423SLionel Sambuc {
54*433d6423SLionel Sambuc 	phys_bytes arg = region->param.phys, phmem;
55*433d6423SLionel Sambuc 	assert(arg != MAP_NONE);
56*433d6423SLionel Sambuc 	assert(ph->ph->phys == MAP_NONE);
57*433d6423SLionel Sambuc 	phmem = arg + ph->offset;
58*433d6423SLionel Sambuc 	assert(phmem != MAP_NONE);
59*433d6423SLionel Sambuc 	ph->ph->phys = phmem;
60*433d6423SLionel Sambuc 	return OK;
61*433d6423SLionel Sambuc }
62*433d6423SLionel Sambuc 
phys_writable(struct phys_region * pr)63*433d6423SLionel Sambuc static int phys_writable(struct phys_region *pr)
64*433d6423SLionel Sambuc {
65*433d6423SLionel Sambuc         assert(pr->ph->refcount > 0);
66*433d6423SLionel Sambuc         return pr->ph->phys != MAP_NONE;
67*433d6423SLionel Sambuc }
68*433d6423SLionel Sambuc 
phys_setphys(struct vir_region * vr,phys_bytes phys)69*433d6423SLionel Sambuc void phys_setphys(struct vir_region *vr, phys_bytes phys)
70*433d6423SLionel Sambuc {
71*433d6423SLionel Sambuc 	vr->param.phys = phys;
72*433d6423SLionel Sambuc }
73*433d6423SLionel Sambuc 
phys_copy(struct vir_region * vr,struct vir_region * newvr)74*433d6423SLionel Sambuc static int phys_copy(struct vir_region *vr, struct vir_region *newvr)
75*433d6423SLionel Sambuc {
76*433d6423SLionel Sambuc 	newvr->param.phys = vr->param.phys;
77*433d6423SLionel Sambuc 
78*433d6423SLionel Sambuc 	return OK;
79*433d6423SLionel Sambuc }
80