1139825Simp/*- 2125184Sgrehan * Copyright (c) 2003 The FreeBSD Project 3125184Sgrehan * All rights reserved. 4125184Sgrehan * 5125184Sgrehan * Redistribution and use in source and binary forms, with or without 6125184Sgrehan * modification, are permitted provided that the following conditions 7125184Sgrehan * are met: 8125184Sgrehan * 9125184Sgrehan * 1. Redistributions of source code must retain the above copyright 10125184Sgrehan * notice, this list of conditions and the following disclaimer. 11125184Sgrehan * 2. Redistributions in binary form must reproduce the above copyright 12125184Sgrehan * notice, this list of conditions and the following disclaimer in the 13125184Sgrehan * documentation and/or other materials provided with the distribution. 14125184Sgrehan * 15125184Sgrehan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16125184Sgrehan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17125184Sgrehan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18125184Sgrehan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19125184Sgrehan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20125184Sgrehan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21125184Sgrehan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22125184Sgrehan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23125184Sgrehan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24125184Sgrehan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25125184Sgrehan */ 26125184Sgrehan 27125184Sgrehan#include <sys/cdefs.h> 28125184Sgrehan__FBSDID("$FreeBSD: releng/10.2/sys/powerpc/aim/uma_machdep.c 243040 2012-11-14 20:01:40Z kib $"); 29125184Sgrehan 30125184Sgrehan#include <sys/param.h> 31125682Sgrehan#include <sys/kernel.h> 32125184Sgrehan#include <sys/lock.h> 33243040Skib#include <sys/malloc.h> 34125184Sgrehan#include <sys/mutex.h> 35125184Sgrehan#include <sys/systm.h> 36125682Sgrehan#include <sys/sysctl.h> 37125184Sgrehan#include <vm/vm.h> 38125184Sgrehan#include <vm/vm_page.h> 39190681Snwhitehorn#include <vm/vm_kern.h> 40125184Sgrehan#include <vm/vm_pageout.h> 41190681Snwhitehorn#include <vm/vm_extern.h> 42125184Sgrehan#include <vm/uma.h> 43190681Snwhitehorn#include <vm/uma.h> 44125184Sgrehan#include <vm/uma_int.h> 45190681Snwhitehorn#include <machine/md_var.h> 46125184Sgrehan#include <machine/vmparam.h> 47125184Sgrehan 48125682Sgrehanstatic int hw_uma_mdpages; 49125682SgrehanSYSCTL_INT(_hw, OID_AUTO, uma_mdpages, CTLFLAG_RD, &hw_uma_mdpages, 0, 50125682Sgrehan "UMA MD pages in use"); 51125682Sgrehan 52125184Sgrehanvoid * 53125184Sgrehanuma_small_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait) 54125184Sgrehan{ 55125184Sgrehan void *va; 56125184Sgrehan vm_page_t m; 57125184Sgrehan int pflags; 58190681Snwhitehorn 59125184Sgrehan *flags = UMA_SLAB_PRIV; 60243040Skib pflags = malloc2vm_flags(wait) | VM_ALLOC_WIRED; 61125184Sgrehan 62125184Sgrehan for (;;) { 63228522Salc m = vm_page_alloc(NULL, 0, pflags | VM_ALLOC_NOOBJ); 64125184Sgrehan if (m == NULL) { 65125184Sgrehan if (wait & M_NOWAIT) 66125184Sgrehan return (NULL); 67125184Sgrehan VM_WAIT; 68125184Sgrehan } else 69125184Sgrehan break; 70125184Sgrehan } 71125184Sgrehan 72125184Sgrehan va = (void *) VM_PAGE_TO_PHYS(m); 73204128Snwhitehorn 74204128Snwhitehorn if (!hw_direct_map) 75204128Snwhitehorn pmap_kenter((vm_offset_t)va, VM_PAGE_TO_PHYS(m)); 76204128Snwhitehorn 77125184Sgrehan if ((wait & M_ZERO) && (m->flags & PG_ZERO) == 0) 78125184Sgrehan bzero(va, PAGE_SIZE); 79125682Sgrehan atomic_add_int(&hw_uma_mdpages, 1); 80125682Sgrehan 81125184Sgrehan return (va); 82125184Sgrehan} 83125184Sgrehan 84125184Sgrehanvoid 85125184Sgrehanuma_small_free(void *mem, int size, u_int8_t flags) 86125184Sgrehan{ 87125184Sgrehan vm_page_t m; 88125184Sgrehan 89204128Snwhitehorn if (!hw_direct_map) 90204128Snwhitehorn pmap_remove(kernel_pmap,(vm_offset_t)mem, 91204128Snwhitehorn (vm_offset_t)mem + PAGE_SIZE); 92190681Snwhitehorn 93204128Snwhitehorn m = PHYS_TO_VM_PAGE((vm_offset_t)mem); 94172189Salc m->wire_count--; 95125184Sgrehan vm_page_free(m); 96172189Salc atomic_subtract_int(&cnt.v_wire_count, 1); 97125682Sgrehan atomic_subtract_int(&hw_uma_mdpages, 1); 98125184Sgrehan} 99