uma_machdep.c revision 166810
183856Sdfr/*- 283856Sdfr * Copyright (c) 2003 Alan L. Cox <alc@cs.rice.edu> 383856Sdfr * All rights reserved. 483856Sdfr * 583856Sdfr * Redistribution and use in source and binary forms, with or without 683856Sdfr * modification, are permitted provided that the following conditions 783856Sdfr * are met: 883856Sdfr * 1. Redistributions of source code must retain the above copyright 983856Sdfr * notice, this list of conditions and the following disclaimer. 1083856Sdfr * 2. Redistributions in binary form must reproduce the above copyright 1183856Sdfr * notice, this list of conditions and the following disclaimer in the 1283856Sdfr * documentation and/or other materials provided with the distribution. 1383856Sdfr * 1483856Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1583856Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1683856Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1783856Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1883856Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1983856Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2083856Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2183856Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2283856Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2383856Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2483856Sdfr * SUCH DAMAGE. 2583856Sdfr */ 2683856Sdfr 2783856Sdfr#include <sys/cdefs.h> 2883856Sdfr__FBSDID("$FreeBSD: head/sys/amd64/amd64/uma_machdep.c 166810 2007-02-18 06:33:02Z alc $"); 2983856Sdfr 3083856Sdfr#include <sys/param.h> 3183856Sdfr#include <sys/lock.h> 3283856Sdfr#include <sys/mutex.h> 3383856Sdfr#include <sys/systm.h> 34110211Smarcel#include <vm/vm.h> 35208283Smarcel#include <vm/vm_page.h> 36208283Smarcel#include <vm/vm_pageout.h> 37208283Smarcel#include <vm/uma.h> 38208283Smarcel#include <vm/uma_int.h> 39208283Smarcel#include <machine/md_var.h> 40208283Smarcel#include <machine/vmparam.h> 41208283Smarcel 4283856Sdfrvoid * 4383856Sdfruma_small_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait) 44208283Smarcel{ 4583856Sdfr static vm_pindex_t colour; 4683856Sdfr vm_page_t m; 4783856Sdfr vm_paddr_t pa; 48208283Smarcel void *va; 49208283Smarcel int pflags; 50208283Smarcel 51208283Smarcel *flags = UMA_SLAB_PRIV; 52208283Smarcel if ((wait & (M_NOWAIT|M_USE_RESERVE)) == M_NOWAIT) 53208283Smarcel pflags = VM_ALLOC_INTERRUPT; 5483856Sdfr else 5583856Sdfr pflags = VM_ALLOC_SYSTEM; 5683856Sdfr if (wait & M_ZERO) 57208283Smarcel pflags |= VM_ALLOC_ZERO; 58208283Smarcel for (;;) { 59208283Smarcel m = vm_page_alloc(NULL, colour++, pflags | VM_ALLOC_NOOBJ); 60208283Smarcel if (m == NULL) { 61208283Smarcel if (wait & M_NOWAIT) 62208283Smarcel return (NULL); 63208283Smarcel else 64208283Smarcel VM_WAIT; 65208283Smarcel } else 66208283Smarcel break; 6783856Sdfr } 6883856Sdfr pa = m->phys_addr; 6983856Sdfr dump_add_page(pa); 70208283Smarcel va = (void *)PHYS_TO_DMAP(pa); 71208283Smarcel if ((wait & M_ZERO) && (m->flags & PG_ZERO) == 0) 72208283Smarcel pagezero(va); 7383856Sdfr return (va); 7483856Sdfr} 7583856Sdfr 76208283Smarcelvoid 77208283Smarceluma_small_free(void *mem, int size, u_int8_t flags) 78208283Smarcel{ 79208283Smarcel vm_page_t m; 80208283Smarcel vm_paddr_t pa; 81208283Smarcel 82208283Smarcel pa = DMAP_TO_PHYS((vm_offset_t)mem); 8383856Sdfr dump_drop_page(pa); 8483856Sdfr m = PHYS_TO_VM_PAGE(pa); 8583856Sdfr vm_page_free(m); 86208283Smarcel} 87208283Smarcel