2 /* This file implements the methods of direct physical mapping.
4 * A direct physical mapping is done by accepting the physical
5 * memory address and range from the caller and allowing direct
6 * access to it. Most significantly, no physical memory is allocated
7 * when it's mapped or freed when it's unmapped. E.g. device memory.
12 /* These functions are static so as to not pollute the
13 * global namespace, and are accessed through their function
17 static int phys_reference(struct phys_region
*pr
);
18 static int phys_unreference(struct phys_region
*pr
);
19 static int phys_writable(struct phys_region
*pr
);
20 static int phys_pagefault(struct vmproc
*vmp
, struct vir_region
*region
,
21 struct phys_region
*ph
, int write
);
22 static int phys_copy(struct vir_region
*vr
, struct vir_region
*newvr
);
24 struct mem_type mem_type_directphys
= {
25 .name
= "physical memory mapping",
26 .ev_reference
= phys_reference
,
28 .ev_unreference
= phys_unreference
,
29 .writable
= phys_writable
,
30 .ev_pagefault
= phys_pagefault
33 static int phys_reference(struct phys_region
*pr
)
35 panic("%s", __FUNCTION__
);
39 static int phys_unreference(struct phys_region
*pr
)
44 static int phys_pagefault(struct vmproc
*vmp
, struct vir_region
*region
,
45 struct phys_region
*ph
, int write
)
47 phys_bytes arg
= region
->param
.phys
, phmem
;
48 assert(arg
!= MAP_NONE
);
49 assert(ph
->ph
->phys
== MAP_NONE
);
50 phmem
= arg
+ ph
->offset
;
51 assert(phmem
!= MAP_NONE
);
56 static int phys_writable(struct phys_region
*pr
)
58 assert(pr
->ph
->refcount
> 0);
59 return pr
->ph
->phys
!= MAP_NONE
;
62 void phys_setphys(struct vir_region
*vr
, phys_bytes phys
)
64 vr
->param
.phys
= phys
;
67 static int phys_copy(struct vir_region
*vr
, struct vir_region
*newvr
)
69 newvr
->param
.phys
= vr
->param
.phys
;