4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * This file contains platform-dependent memory support routines,
30 * suitable for memory methods with 2-cell physical addresses.
31 * Use of these routines makes the caller platform-dependent,
32 * since the caller assumes knowledge of the physical layout of
33 * the machines address space. Generic programs should use the
34 * standard client interface memory allocators.
37 #include <sys/promif.h>
38 #include <sys/promimpl.h>
41 prom_memory_ihandle(void)
43 static ihandle_t imemory
;
45 if (imemory
!= (ihandle_t
)0)
48 if (prom_getproplen(prom_chosennode(), "memory") != sizeof (ihandle_t
))
49 return (imemory
= (ihandle_t
)-1);
51 (void) prom_getprop(prom_chosennode(), "memory", (caddr_t
)(&imemory
));
56 * Allocate physical memory, unmapped and possibly aligned.
57 * Returns 0: Success; Non-zero: failure.
58 * Returns *physaddr only if successful.
60 * This routine is suitable for platforms with 2-cell physical addresses
61 * and a single size cell in the "memory" node.
64 prom_allocate_phys(size_t size
, uint_t align
, unsigned long long *physaddr
)
68 ihandle_t imemory
= prom_memory_ihandle();
70 if ((imemory
== (ihandle_t
)-1))
76 ci
[0] = p1275_ptr2cell("call-method"); /* Service name */
77 ci
[1] = (cell_t
)4; /* #argument cells */
78 ci
[2] = (cell_t
)3; /* #result cells */
79 ci
[3] = p1275_ptr2cell("claim"); /* Arg1: Method name */
80 ci
[4] = p1275_ihandle2cell(imemory
); /* Arg2: memory ihandle */
81 ci
[5] = p1275_uint2cell(align
); /* Arg3: SA1: align */
82 ci
[6] = p1275_size2cell(size
); /* Arg4: SA2: size */
85 rv
= p1275_cif_handler(&ci
);
90 if (p1275_cell2int(ci
[7]) != 0) /* Res1: Catch result */
93 *physaddr
= p1275_cells2ull(ci
[8], ci
[9]);
94 /* Res2: SR1: phys.hi ... Res3: SR2: phys.lo */
99 * Claim a region of physical memory, unmapped.
100 * Returns 0: Success; Non-zero: failure.
102 * This routine is suitable for platforms with 2-cell physical addresses
103 * and a single size cell in the "memory" node.
106 prom_claim_phys(size_t size
, unsigned long long physaddr
)
110 ihandle_t imemory
= prom_memory_ihandle();
112 if ((imemory
== (ihandle_t
)-1))
115 ci
[0] = p1275_ptr2cell("call-method"); /* Service name */
116 ci
[1] = (cell_t
)6; /* #argument cells */
117 ci
[2] = (cell_t
)1; /* #result cells */
118 ci
[3] = p1275_ptr2cell("claim"); /* Arg1: Method name */
119 ci
[4] = p1275_ihandle2cell(imemory
); /* Arg2: mmu ihandle */
120 ci
[5] = 0; /* Arg3: SA1: align */
121 ci
[6] = p1275_size2cell(size
); /* Arg4: SA2: len */
122 ci
[7] = p1275_ull2cell_high(physaddr
); /* Arg5: SA3: phys.hi */
123 ci
[8] = p1275_ull2cell_low(physaddr
); /* Arg6: SA4: phys.lo */
126 rv
= p1275_cif_handler(&ci
);
131 if (p1275_cell2int(ci
[9]) != 0) /* Res1: Catch result */
138 * Free physical memory (no unmapping is done).
139 * This routine is suitable for platforms with 2-cell physical addresses
140 * with a single size cell.
143 prom_free_phys(size_t size
, unsigned long long physaddr
)
146 ihandle_t imemory
= prom_memory_ihandle();
148 if ((imemory
== (ihandle_t
)-1))
151 ci
[0] = p1275_ptr2cell("call-method"); /* Service name */
152 ci
[1] = (cell_t
)5; /* #argument cells */
153 ci
[2] = (cell_t
)0; /* #return cells */
154 ci
[3] = p1275_ptr2cell("release"); /* Arg1: Method name */
155 ci
[4] = p1275_ihandle2cell(imemory
); /* Arg2: memory ihandle */
156 ci
[5] = p1275_size2cell(size
); /* Arg3: SA1: size */
157 ci
[6] = p1275_ull2cell_high(physaddr
); /* Arg4: SA2: phys.hi */
158 ci
[7] = p1275_ull2cell_low(physaddr
); /* Arg5: SA3: phys.lo */
161 (void) p1275_cif_handler(&ci
);
166 prom_mem_phandle(void)
168 static pnode_t pmem
= 0;
170 if (pmem
== (pnode_t
)0) {
173 if ((ih
= prom_memory_ihandle()) == (ihandle_t
)-1)
174 prom_panic("Can't get memory ihandle");
175 pmem
= prom_getphandle(ih
);
182 prom_phys_installed_len(void)
184 return (prom_getproplen(prom_mem_phandle(), "reg"));
188 prom_phys_avail_len(void)
190 return (prom_getproplen(prom_mem_phandle(), "available"));
194 prom_phys_installed(caddr_t prop
)
196 return (prom_getprop(prom_mem_phandle(), "reg", prop
));
200 prom_phys_avail(caddr_t prop
)
202 return (prom_getprop(prom_mem_phandle(), "available", prop
));