xref: /onnv-gate/usr/src/stand/lib/sa/standalloc.c (revision 785:a0797646b335)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*785Seota  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/saio.h>
310Sstevel@tonic-gate #include <sys/sysmacros.h>
320Sstevel@tonic-gate #include <sys/promif.h>
330Sstevel@tonic-gate #include <sys/bootconf.h>
340Sstevel@tonic-gate #include <sys/salib.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #ifdef DEBUG
370Sstevel@tonic-gate static int	resalloc_debug = 1;
380Sstevel@tonic-gate #else /* DEBUG */
390Sstevel@tonic-gate static int	resalloc_debug = 0;
400Sstevel@tonic-gate #endif /* DEBUG */
410Sstevel@tonic-gate #define	dprintf	if (resalloc_debug) printf
420Sstevel@tonic-gate 
430Sstevel@tonic-gate extern	caddr_t		resalloc(enum RESOURCES type,
440Sstevel@tonic-gate 				size_t bytes, caddr_t virthint, int align);
450Sstevel@tonic-gate extern	void		resfree(enum RESOURCES type,
460Sstevel@tonic-gate 				caddr_t virtaddr, size_t bytes);
470Sstevel@tonic-gate 
480Sstevel@tonic-gate caddr_t		memlistpage;
490Sstevel@tonic-gate extern int	pagesize;
500Sstevel@tonic-gate 
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate  *  This routine should be called get_a_page().
530Sstevel@tonic-gate  *  It allocates from the appropriate entity one or
540Sstevel@tonic-gate  *  more pages and maps them in.
550Sstevel@tonic-gate  */
560Sstevel@tonic-gate 
570Sstevel@tonic-gate caddr_t
kern_resalloc(caddr_t virthint,size_t size,int align)580Sstevel@tonic-gate kern_resalloc(caddr_t virthint, size_t size, int align)
590Sstevel@tonic-gate {
600Sstevel@tonic-gate 	if (virthint != 0)
610Sstevel@tonic-gate 		return (resalloc(RES_CHILDVIRT, size, virthint, align));
620Sstevel@tonic-gate 	else {
630Sstevel@tonic-gate 		return (resalloc(RES_BOOTSCRATCH, size, NULL, NULL));
640Sstevel@tonic-gate 	}
650Sstevel@tonic-gate }
660Sstevel@tonic-gate 
670Sstevel@tonic-gate /*
680Sstevel@tonic-gate  * This is called only on sparcv9 for freeing scratch memory.
690Sstevel@tonic-gate  * The standalone allocator cannot free other types of memory.
700Sstevel@tonic-gate  */
710Sstevel@tonic-gate void
kern_resfree(caddr_t virtaddr,size_t size)720Sstevel@tonic-gate kern_resfree(caddr_t virtaddr, size_t size)
730Sstevel@tonic-gate {
740Sstevel@tonic-gate 	resfree(RES_BOOTSCRATCH, virtaddr, size);
750Sstevel@tonic-gate }
760Sstevel@tonic-gate 
770Sstevel@tonic-gate int
get_progmemory(caddr_t vaddr,size_t size,int align)780Sstevel@tonic-gate get_progmemory(caddr_t vaddr, size_t size, int align)
790Sstevel@tonic-gate {
80*785Seota 	uintptr_t n;
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 	/*
830Sstevel@tonic-gate 	 * if the vaddr given is not a mult of PAGESIZE,
840Sstevel@tonic-gate 	 * then we rounddown to a page, but keep the same
850Sstevel@tonic-gate 	 * ending addr.
860Sstevel@tonic-gate 	 */
87*785Seota 	n = (uintptr_t)vaddr & (pagesize - 1);
880Sstevel@tonic-gate 	if (n) {
890Sstevel@tonic-gate 		vaddr -= n;
900Sstevel@tonic-gate 		size += n;
910Sstevel@tonic-gate 	}
920Sstevel@tonic-gate 
930Sstevel@tonic-gate 	dprintf("get_progmemory: requesting %lx bytes at %p\n", size,
940Sstevel@tonic-gate 	    (void *)vaddr);
950Sstevel@tonic-gate 	if (resalloc(RES_CHILDVIRT, size, vaddr, align) != vaddr)
960Sstevel@tonic-gate 		return (-1);
970Sstevel@tonic-gate 	return (0);
980Sstevel@tonic-gate }
99