2 * Copyright (c) 2011 NetApp, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
34 #include <sys/mutex.h>
35 #include <sys/linker.h>
36 #include <sys/systm.h>
37 #include <sys/malloc.h>
38 #include <sys/kernel.h>
39 #include <sys/sysctl.h>
43 #include <vm/vm_page.h>
44 #include <vm/vm_pageout.h>
46 #include <machine/md_var.h>
47 #include <machine/metadata.h>
48 #include <machine/pc/bios.h>
49 #include <machine/vmparam.h>
50 #include <machine/pmap.h>
57 static u_long pages_allocated;
58 SYSCTL_ULONG(_hw_vmm, OID_AUTO, pages_allocated, CTLFLAG_RD,
59 &pages_allocated, 0, "4KB pages allocated");
62 update_pages_allocated(int howmany)
64 pages_allocated += howmany; /* XXX locking? */
75 vmm_mem_alloc(size_t size)
81 if (size != PAGE_SIZE)
82 panic("vmm_mem_alloc: invalid allocation size %lu", size);
84 flags = VM_ALLOC_NORMAL | VM_ALLOC_NOOBJ | VM_ALLOC_WIRED |
89 * XXX need policy to determine when to back off the allocation
91 m = vm_page_alloc(NULL, 0, flags);
98 pa = VM_PAGE_TO_PHYS(m);
100 if ((m->flags & PG_ZERO) == 0)
101 pagezero((void *)PHYS_TO_DMAP(pa));
102 m->valid = VM_PAGE_BITS_ALL;
104 update_pages_allocated(1);
110 vmm_mem_free(vm_paddr_t base, size_t length)
114 if (base & PAGE_MASK) {
115 panic("vmm_mem_free: base 0x%0lx must be aligned on a "
116 "0x%0x boundary\n", base, PAGE_SIZE);
119 if (length != PAGE_SIZE)
120 panic("vmm_mem_free: invalid length %lu", length);
122 m = PHYS_TO_VM_PAGE(base);
125 atomic_subtract_int(&cnt.v_wire_count, 1);
127 update_pages_allocated(-1);
131 vmm_mem_maxaddr(void)
134 return (ptoa(Maxmem));