xref: /titanic_50/usr/src/psm/promif/ieee1275/sun4/prom_map.c (revision c77a61a72b5ecdc507d6cf104142edd371a16c84)
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) 1991-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  * Mapping routines suitable for implementations using 2-cell physical
34  * address formats.  Use of these routines makes the caller
35  * platform-dependent.  The implementation of these routines is
36  * a bit sun-hardware centric, for historical use by SunOS and standalones.
37  */
38 
39 caddr_t
40 prom_map(caddr_t virthint, unsigned long long physaddr, u_int size)
41 {
42 	caddr_t virt;
43 
44 	/*
45 	 * If no virthint, allocate it; otherwise claim it,
46 	 * the physical address is assumed to be a device or
47 	 * already claimed, or not appearing in a resource list.
48 	 */
49 	if (virthint == (caddr_t)0)  {
50 		if ((virt = prom_allocate_virt((u_int)1, size)) == 0)
51 			return ((caddr_t)0);
52 	} else {
53 		virt = virthint;
54 		if (prom_claim_virt(size, virt) != virt)
55 			return ((caddr_t)0);
56 	}
57 
58 	if (prom_map_phys(-1, size, virt, physaddr) != 0) {
59 		/*
60 		 * The map operation failed, free the virtual
61 		 * addresses we allocated or claimed.
62 		 */
63 		(void) prom_free_virt(size, virt);
64 		return ((caddr_t)0);
65 	}
66 	return (virt);
67 }
68 
69 void
70 prom_unmap(caddr_t virt, u_int size)
71 {
72 	(void) prom_unmap_virt(size, virt);
73 	prom_free_virt(size, virt);
74 }
75