2 /* This file implements the methods of physically contiguous anonymous memory. */
11 static int anon_contig_reference(struct phys_region
*, struct phys_region
*);
12 static int anon_contig_unreference(struct phys_region
*pr
);
13 static int anon_contig_pagefault(struct vmproc
*vmp
, struct vir_region
*region
,
14 struct phys_region
*ph
, int write
, vfs_callback_t cb
, void *state
,
16 static int anon_contig_sanitycheck(struct phys_region
*pr
, const char *file
, int line
);
17 static int anon_contig_writable(struct phys_region
*pr
);
18 static int anon_contig_resize(struct vmproc
*vmp
, struct vir_region
*vr
, vir_bytes l
);
19 static int anon_contig_new(struct vir_region
*vr
);
20 static int anon_contig_pt_flags(struct vir_region
*vr
);
22 struct mem_type mem_type_anon_contig
= {
23 .name
= "anonymous memory (physically contiguous)",
24 .ev_new
= anon_contig_new
,
25 .ev_reference
= anon_contig_reference
,
26 .ev_unreference
= anon_contig_unreference
,
27 .ev_pagefault
= anon_contig_pagefault
,
28 .ev_resize
= anon_contig_resize
,
29 .ev_sanitycheck
= anon_contig_sanitycheck
,
30 .writable
= anon_contig_writable
,
31 .pt_flags
= anon_contig_pt_flags
,
34 static int anon_contig_pt_flags(struct vir_region
*vr
){
36 return ARM_VM_PTE_DEVICE
;
42 static int anon_contig_pagefault(struct vmproc
*vmp
, struct vir_region
*region
,
43 struct phys_region
*ph
, int write
, vfs_callback_t cb
, void *state
,
46 panic("anon_contig_pagefault: pagefault cannot happen");
49 static int anon_contig_new(struct vir_region
*region
)
52 phys_bytes new_pages
, new_page_cl
, cur_ph
;
55 allocflags
= vrallocflags(region
->flags
);
57 pages
= region
->length
/VM_PAGE_SIZE
;
59 assert(physregions(region
) == 0);
61 for(p
= 0; p
< pages
; p
++) {
62 struct phys_block
*pb
= pb_new(MAP_NONE
);
63 struct phys_region
*pr
= NULL
;
65 pr
= pb_reference(pb
, p
* VM_PAGE_SIZE
, region
, &mem_type_anon_contig
);
73 assert(physregions(region
) == pages
);
75 if((new_page_cl
= alloc_mem(pages
, allocflags
)) == NO_MEM
) {
80 cur_ph
= new_pages
= CLICK2ABS(new_page_cl
);
82 for(p
= 0; p
< pages
; p
++) {
83 struct phys_region
*pr
= physblock_get(region
, p
* VM_PAGE_SIZE
);
86 assert(pr
->ph
->phys
== MAP_NONE
);
87 assert(pr
->offset
== p
* VM_PAGE_SIZE
);
88 pr
->ph
->phys
= cur_ph
+ pr
->offset
;
94 static int anon_contig_resize(struct vmproc
*vmp
, struct vir_region
*vr
, vir_bytes l
)
96 printf("VM: cannot resize physically contiguous memory.\n");
100 static int anon_contig_reference(struct phys_region
*pr
,
101 struct phys_region
*newpr
)
103 printf("VM: cannot fork with physically contig memory.\n");
107 /* Methods inherited from the anonymous memory methods. */
109 static int anon_contig_unreference(struct phys_region
*pr
)
111 return mem_type_anon
.ev_unreference(pr
);
114 static int anon_contig_sanitycheck(struct phys_region
*pr
, const char *file
, int line
)
116 return mem_type_anon
.ev_sanitycheck(pr
, file
, line
);
119 static int anon_contig_writable(struct phys_region
*pr
)
121 return mem_type_anon
.writable(pr
);