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.
15 /* These functions are static so as to not pollute the
16 * global namespace, and are accessed through their function
20 static int phys_unreference(struct phys_region
*pr
);
21 static int phys_writable(struct phys_region
*pr
);
22 static int phys_pagefault(struct vmproc
*vmp
, struct vir_region
*region
,
23 struct phys_region
*ph
, int write
, vfs_callback_t cb
, void *state
,
25 static int phys_copy(struct vir_region
*vr
, struct vir_region
*newvr
);
26 static int phys_pt_flags(struct vir_region
*vr
);
28 struct mem_type mem_type_directphys
= {
29 .name
= "physical memory mapping",
31 .ev_unreference
= phys_unreference
,
32 .writable
= phys_writable
,
33 .ev_pagefault
= phys_pagefault
,
34 .pt_flags
= phys_pt_flags
37 static int phys_pt_flags(struct vir_region
*vr
){
39 return ARM_VM_PTE_DEVICE
;
45 static int phys_unreference(struct phys_region
*pr
)
50 static int phys_pagefault(struct vmproc
*vmp
, struct vir_region
*region
,
51 struct phys_region
*ph
, int write
, vfs_callback_t cb
, void *state
,
54 phys_bytes arg
= region
->param
.phys
, phmem
;
55 assert(arg
!= MAP_NONE
);
56 assert(ph
->ph
->phys
== MAP_NONE
);
57 phmem
= arg
+ ph
->offset
;
58 assert(phmem
!= MAP_NONE
);
63 static int phys_writable(struct phys_region
*pr
)
65 assert(pr
->ph
->refcount
> 0);
66 return pr
->ph
->phys
!= MAP_NONE
;
69 void phys_setphys(struct vir_region
*vr
, phys_bytes phys
)
71 vr
->param
.phys
= phys
;
74 static int phys_copy(struct vir_region
*vr
, struct vir_region
*newvr
)
76 newvr
->param
.phys
= vr
->param
.phys
;