xref: /illumos-gate/usr/src/lib/udapl/udapl_tavor/common/dapl_mr_util.c (revision 9e39c5ba00a55fa05777cc94b148296af305e135)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
24  */
25 
26 /*
27  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #include "dapl_mr_util.h"
32 
33 /*
34  *
35  * MODULE: dapl_mr_util.c
36  *
37  * PURPOSE: Common Memory Management functions and data structures
38  *
39  */
40 
41 /*
42  *
43  * Function Definitions
44  *
45  */
46 
47 /*
48  * dapl_mr_get_address
49  *
50  * Returns the memory address associated with the given memory descriptor
51  *
52  */
53 DAT_VADDR
dapl_mr_get_address(DAT_REGION_DESCRIPTION desc,DAT_MEM_TYPE type)54 dapl_mr_get_address(DAT_REGION_DESCRIPTION desc, DAT_MEM_TYPE type)
55 {
56 	switch (type) {
57 	case DAT_MEM_TYPE_VIRTUAL: {
58 		return ((DAT_VADDR)(uintptr_t)desc.for_va);
59 	}
60 	case DAT_MEM_TYPE_LMR: {
61 		DAPL_LMR 	*lmr;
62 
63 		lmr = (DAPL_LMR *)desc.for_lmr_handle;
64 
65 		/* Since this function is recoursive we cannot inline it */
66 		return (dapl_mr_get_address(lmr->param.region_desc,
67 		    lmr->param.mem_type));
68 	}
69 	case DAT_MEM_TYPE_SHARED_VIRTUAL: {
70 		return ((DAT_VADDR)(uintptr_t)
71 		    desc.for_shared_memory.virtual_address);
72 	}
73 	default:
74 		dapl_os_assert(0);
75 		return (0);
76 	}
77 }
78 
79 /*
80  * dapl_mr_bounds_check
81  *
82  * Returns true if region B is contained within region A
83  * and false otherwise
84  *
85  */
86 DAT_BOOLEAN
dapl_mr_bounds_check(DAT_VADDR addr_a,DAT_VLEN length_a,DAT_VADDR addr_b,DAT_VLEN length_b)87 dapl_mr_bounds_check(DAT_VADDR addr_a, DAT_VLEN length_a,
88 	DAT_VADDR addr_b, DAT_VLEN length_b)
89 {
90 	if ((addr_a <= addr_b) &&
91 	    (addr_b + length_b) <= (addr_a + length_a)) {
92 		return (DAT_TRUE);
93 	} else {
94 		return (DAT_FALSE);
95 	}
96 }
97