1 |
/* VM page. |
/* VM page. |
2 |
Copyright 1999, 2000, 2001 Johan Rydberg, jrydberg@opencores.org. |
Copyright 1999, 2000, 2001, 2002 Johan Rydberg, jrydberg@opencores.org. |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
61 |
|
|
62 |
/* Cache for VM page structures. Might come handy. */ |
/* Cache for VM page structures. Might come handy. */ |
63 |
static struct kmem_cache *page_cache; |
static struct kmem_cache *page_cache; |
64 |
|
static struct kmem_cache *fict_cache; |
65 |
|
|
66 |
/* Initialize page stuff that is needed after the VM system is bootstrapped. */ |
/* Initialize page stuff that is needed after the VM system is bootstrapped. */ |
67 |
|
|
70 |
{ |
{ |
71 |
page_cache = kmem_cache_create ("page cache", |
page_cache = kmem_cache_create ("page cache", |
72 |
sizeof (struct vm_page), 0); |
sizeof (struct vm_page), 0); |
73 |
assert (page_cache); |
fict_cache = kmem_cache_create ("fict cache", |
74 |
|
sizeof (struct vm_page), 0); |
75 |
|
assert (page_cache && fict_cache); |
76 |
} |
} |
77 |
|
|
78 |
|
|
194 |
|
|
195 |
|
|
196 |
/* Release PAGE. Put it on the free list. */ |
/* Release PAGE. Put it on the free list. */ |
|
|
|
197 |
void |
void |
198 |
vm_page_release (struct vm_page *page) |
vm_page_release (struct vm_page *page) |
199 |
{ |
{ |
200 |
/* ??? is this the correct macro? */ |
if (page->fictitious_p) |
201 |
page_free_count++; |
{ |
202 |
queue_enter (&page_free_list, page, struct vm_page *, listq); |
kmem_cache_free (fict_cache, page); |
203 |
|
} |
204 |
|
else |
205 |
|
{ |
206 |
|
page_free_count++; |
207 |
|
queue_enter (&page_free_list, page, struct vm_page *, listq); |
208 |
|
} |
209 |
} |
} |
210 |
|
|
211 |
/* Allocate a new page from the free list. This may start the |
/* Allocate a new page from the free list. This may start the |
225 |
return page; |
return page; |
226 |
} |
} |
227 |
|
|
228 |
|
/* Allocate a fictitious page. We returned page have no |
229 |
|
physical page assigned. On failure NULL is returned. */ |
230 |
|
|
231 |
|
struct vm_page * |
232 |
|
vm_page_fictitious_allocate (void) |
233 |
|
{ |
234 |
|
struct vm_page *page; |
235 |
|
|
236 |
|
page = (struct vm_page *) kmem_cache_alloc (fict_cache); |
237 |
|
if (page) |
238 |
|
{ |
239 |
|
memset (page, 0, sizeof (struct vm_page)); |
240 |
|
page->fictitious_p = true; |
241 |
|
} |
242 |
|
return page; |
243 |
|
} |
244 |
|
|
245 |
|
/* Assign a physical address, PA, to PAGE. */ |
246 |
|
|
247 |
|
void |
248 |
|
vm_page_assign (struct vm_page *page, vm_offset_t pa) |
249 |
|
{ |
250 |
|
ASSERT (page->fictitious_p == true); |
251 |
|
page->phys_addr = pa; |
252 |
|
} |
253 |
|
|
254 |
|
|
255 |
/* Grab a physical page. The physical page address is returned. */ |
/* Grab a physical page. The physical page address is returned. */ |
256 |
|
|
257 |
void * |
void * |