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
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.
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]
23 * Copyright (c) 1991-1994, by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/promif.h>
30 #include <sys/promimpl.h>
33 * This allocator has SMCC-OBP-like semantics associated with it.
34 * Specifically, the alignment value specifies both a physical
35 * and virtual alignment. If virthint is zero, a suitable virt
36 * is chosen. In either case, align is not ignored.
38 * This routine returns NULL on failure.
39 * This routine is suitable for (the given semantics) machines with
40 * a 2-cell physical address.
42 * Memory allocated with prom_alloc can be freed with prom_free.
44 * The generic allocator is prom_malloc.
49 prom_alloc(caddr_t virthint
, size_t size
, u_int align
)
52 caddr_t virt
= virthint
;
53 unsigned long long physaddr
;
59 * First, allocate or claim the virtual address space.
60 * In either case, after this code, "virt" is the chosen address.
63 virt
= prom_allocate_virt(align
, size
);
64 if (virt
== (caddr_t
)-1)
67 if (prom_claim_virt(size
, virthint
) == (caddr_t
)-1)
72 * Next, allocate the physical address space, at the specified
73 * physical alignment (or 1 byte alignment, if none specified)
76 if (prom_allocate_phys(size
, align
, &physaddr
) == -1) {
79 * Request failed, free virtual address space and return.
81 prom_free_virt(size
, virt
);
86 * Next, create a mapping from the physical to virtual address,
87 * using a default "mode".
90 if (prom_map_phys(-1, size
, virt
, physaddr
) == -1) {
93 * The call failed; release the physical and virtual
94 * addresses allocated or claimed, and return.
97 prom_free_virt(size
, virt
);
98 prom_free_phys(size
, physaddr
);
105 * This is the generic client interface to "claim" memory.
106 * These two routines belong in the common directory.
109 prom_malloc(caddr_t virt
, size_t size
, u_int align
)
114 ci
[0] = p1275_ptr2cell("claim"); /* Service name */
115 ci
[1] = (cell_t
)3; /* #argument cells */
116 ci
[2] = (cell_t
)1; /* #result cells */
117 ci
[3] = p1275_ptr2cell(virt
); /* Arg1: virt */
118 ci
[4] = p1275_size2cell(size
); /* Arg2: size */
119 ci
[5] = p1275_uint2cell(align
); /* Arg3: align */
122 rv
= p1275_cif_handler(&ci
);
126 return ((caddr_t
)p1275_cell2ptr(ci
[6])); /* Res1: base */
127 return ((caddr_t
)-1);
132 prom_free(caddr_t virt
, size_t size
)
136 ci
[0] = p1275_ptr2cell("release"); /* Service name */
137 ci
[1] = (cell_t
)2; /* #argument cells */
138 ci
[2] = (cell_t
)0; /* #result cells */
139 ci
[3] = p1275_ptr2cell(virt
); /* Arg1: virt */
140 ci
[4] = p1275_size2cell(size
); /* Arg2: size */
143 (void) p1275_cif_handler(&ci
);