xref: /freebsd/sys/amd64/amd64/uma_machdep.c (revision fdafd315)
17fb57893SAlan Cox /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3c49761ddSPedro F. Giffuni  *
47fb57893SAlan Cox  * Copyright (c) 2003 Alan L. Cox <alc@cs.rice.edu>
57fb57893SAlan Cox  * All rights reserved.
67fb57893SAlan Cox  *
77fb57893SAlan Cox  * Redistribution and use in source and binary forms, with or without
87fb57893SAlan Cox  * modification, are permitted provided that the following conditions
97fb57893SAlan Cox  * are met:
107fb57893SAlan Cox  * 1. Redistributions of source code must retain the above copyright
117fb57893SAlan Cox  *    notice, this list of conditions and the following disclaimer.
127fb57893SAlan Cox  * 2. Redistributions in binary form must reproduce the above copyright
137fb57893SAlan Cox  *    notice, this list of conditions and the following disclaimer in the
147fb57893SAlan Cox  *    documentation and/or other materials provided with the distribution.
157fb57893SAlan Cox  *
167fb57893SAlan Cox  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
177fb57893SAlan Cox  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
187fb57893SAlan Cox  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
197fb57893SAlan Cox  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
207fb57893SAlan Cox  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
217fb57893SAlan Cox  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
227fb57893SAlan Cox  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
237fb57893SAlan Cox  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
247fb57893SAlan Cox  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
257fb57893SAlan Cox  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
267fb57893SAlan Cox  * SUCH DAMAGE.
277fb57893SAlan Cox  */
287fb57893SAlan Cox 
297fb57893SAlan Cox #include <sys/param.h>
30b32ecf44SKonstantin Belousov #include <sys/malloc.h>
317fb57893SAlan Cox #include <vm/vm.h>
326f3b523cSKonstantin Belousov #include <vm/vm_param.h>
337fb57893SAlan Cox #include <vm/vm_page.h>
3431991a5aSMitchell Horne #include <vm/vm_phys.h>
356f3b523cSKonstantin Belousov #include <vm/vm_dumpset.h>
367fb57893SAlan Cox #include <vm/uma.h>
377fb57893SAlan Cox #include <vm/uma_int.h>
387fb57893SAlan Cox #include <machine/md_var.h>
397fb57893SAlan Cox 
407fb57893SAlan Cox void *
uma_small_alloc(uma_zone_t zone,vm_size_t bytes,int domain,u_int8_t * flags,int wait)41ab3185d1SJeff Roberson uma_small_alloc(uma_zone_t zone, vm_size_t bytes, int domain, u_int8_t *flags,
42ab3185d1SJeff Roberson     int wait)
437fb57893SAlan Cox {
447fb57893SAlan Cox 	vm_page_t m;
45c0345a84SPeter Wemm 	vm_paddr_t pa;
467fb57893SAlan Cox 	void *va;
477fb57893SAlan Cox 
487fb57893SAlan Cox 	*flags = UMA_SLAB_PRIV;
49a4667e09SMark Johnston 	m = vm_page_alloc_noobj_domain(domain, malloc2vm_flags(wait) |
50a4667e09SMark Johnston 	    VM_ALLOC_WIRED);
518d6fbbb8SJeff Roberson 	if (m == NULL)
527fb57893SAlan Cox 		return (NULL);
53c0345a84SPeter Wemm 	pa = m->phys_addr;
54263811f7SKip Macy 	if ((wait & M_NODUMP) == 0)
55c0345a84SPeter Wemm 		dump_add_page(pa);
56c0345a84SPeter Wemm 	va = (void *)PHYS_TO_DMAP(pa);
577fb57893SAlan Cox 	return (va);
587fb57893SAlan Cox }
597fb57893SAlan Cox 
607fb57893SAlan Cox void
uma_small_free(void * mem,vm_size_t size,u_int8_t flags)61f2c2231eSRyan Stone uma_small_free(void *mem, vm_size_t size, u_int8_t flags)
627fb57893SAlan Cox {
637fb57893SAlan Cox 	vm_page_t m;
64c0345a84SPeter Wemm 	vm_paddr_t pa;
657fb57893SAlan Cox 
66c0345a84SPeter Wemm 	pa = DMAP_TO_PHYS((vm_offset_t)mem);
67c0345a84SPeter Wemm 	dump_drop_page(pa);
68c0345a84SPeter Wemm 	m = PHYS_TO_VM_PAGE(pa);
69ab7c09f1SMark Johnston 	vm_page_unwire_noq(m);
707fb57893SAlan Cox 	vm_page_free(m);
717fb57893SAlan Cox }
72