xref: /titanic_52/usr/src/psm/promif/ieee1275/sun4/prom_retain.c (revision fa9e4066f08beec538e775443c5be79dd423fcab)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1994, by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/promif.h>
30 #include <sys/promimpl.h>
31 
32 /*
33  * Allocate retained physical memory
34  * Returns 0: Success; Non-zero: failure.
35  * Returns *phys_hi, *phys_lo only if successful.
36  */
37 int
38 prom_retain(char *id, size_t size, u_int align, unsigned long long *physaddr)
39 {
40 	cell_t ci[11];
41 	int rv;
42 	ihandle_t imemory = prom_memory_ihandle();
43 
44 	if ((imemory == (ihandle_t)-1))
45 		return (-1);
46 
47 	ci[0] = p1275_ptr2cell("call-method");	/* Service name */
48 	ci[1] = (cell_t)5;			/* #argument cells */
49 	ci[2] = (cell_t)3;			/* #result cells */
50 	ci[3] = p1275_ptr2cell("SUNW,retain");	/* Arg1: Method name */
51 	ci[4] = p1275_ihandle2cell(imemory);	/* Arg2: memory ihandle */
52 	ci[5] = p1275_uint2cell(align);		/* Arg2: SA1: align */
53 	ci[6] = p1275_size2cell(size);		/* Arg3: SA2: size */
54 	ci[7] = p1275_ptr2cell(id);		/* Arg4: SA3: id name */
55 
56 	promif_preprom();
57 	rv = p1275_cif_handler(&ci);
58 	promif_postprom();
59 
60 	if (rv != 0)
61 		return (rv);		/* Service "call-method" failed */
62 	if (ci[8] != 0)			/* Res1: catch-result */
63 		return (-1);		/* Method "SUNW,retain" failed */
64 
65 	*physaddr = p1275_cells2ull(ci[9], ci[10]);
66 					/* Res3: base.hi, Res4: base.lo */
67 	return (0);
68 }
69