xref: /onnv-gate/usr/src/uts/common/os/ddi_nodeid.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright (c) 1999 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate  * DDI nodeid management ...
31*0Sstevel@tonic-gate  */
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate #include <sys/types.h>
34*0Sstevel@tonic-gate #include <sys/ksynch.h>
35*0Sstevel@tonic-gate #include <sys/kmem.h>
36*0Sstevel@tonic-gate #include <sys/cmn_err.h>
37*0Sstevel@tonic-gate #include <sys/ddi.h>
38*0Sstevel@tonic-gate #include <sys/sunddi.h>
39*0Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
40*0Sstevel@tonic-gate #include <sys/ddi_implfuncs.h>
41*0Sstevel@tonic-gate #include <sys/debug.h>
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate /*
44*0Sstevel@tonic-gate  * Keep a sorted free list of available nodeids.
45*0Sstevel@tonic-gate  * Allocating a nodeid won't cause memory allocation.
46*0Sstevel@tonic-gate  * Freeing a nodeid does cause memory allocation.
47*0Sstevel@tonic-gate  */
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate struct available {
50*0Sstevel@tonic-gate 	uint32_t nodeid;
51*0Sstevel@tonic-gate 	uint32_t count;
52*0Sstevel@tonic-gate 	struct available *next;
53*0Sstevel@tonic-gate 	struct available *prev;
54*0Sstevel@tonic-gate };
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate /*
57*0Sstevel@tonic-gate  * The initial seed of available nodeids: 1 .. 0x10000000
58*0Sstevel@tonic-gate  * 0, -1 (DEVI_PSEUDO_NODEID) and -2 (DEVI_SID_NODEID) are illegal values
59*0Sstevel@tonic-gate  * and may not be used.  Although this code is fully capable of dealing
60*0Sstevel@tonic-gate  * with a full 32-bit range of nodeids, we use a low numeric range of
61*0Sstevel@tonic-gate  * nodeids as an optimization to avoid overlap with promif nodeids.
62*0Sstevel@tonic-gate  */
63*0Sstevel@tonic-gate #define	OUR_NODEID_MIN		((uint32_t)1)
64*0Sstevel@tonic-gate #define	OUR_NODEID_MAX		((uint32_t)0x10000000)
65*0Sstevel@tonic-gate #define	OUR_NODEID_COUNT	((uint32_t)(OUR_NODEID_MAX - OUR_NODEID_MIN))
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate static struct available seed = {
68*0Sstevel@tonic-gate 	OUR_NODEID_MIN, OUR_NODEID_COUNT, NULL, NULL
69*0Sstevel@tonic-gate };
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate /*
72*0Sstevel@tonic-gate  * head of the available list ...
73*0Sstevel@tonic-gate  */
74*0Sstevel@tonic-gate static struct available *nhead;
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate /*
77*0Sstevel@tonic-gate  * A single lock for the list ...
78*0Sstevel@tonic-gate  */
79*0Sstevel@tonic-gate static kmutex_t nodeid_lock;
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate /*
82*0Sstevel@tonic-gate  * Helper functions to manage the list ...
83*0Sstevel@tonic-gate  */
84*0Sstevel@tonic-gate static struct available *
np_alloc(int kmflag)85*0Sstevel@tonic-gate np_alloc(int kmflag)
86*0Sstevel@tonic-gate {
87*0Sstevel@tonic-gate 	return (kmem_zalloc(sizeof (struct available), kmflag));
88*0Sstevel@tonic-gate }
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate static void
np_free(struct available * np)91*0Sstevel@tonic-gate np_free(struct available *np)
92*0Sstevel@tonic-gate {
93*0Sstevel@tonic-gate 	kmem_free(np, sizeof (struct available));
94*0Sstevel@tonic-gate }
95*0Sstevel@tonic-gate 
96*0Sstevel@tonic-gate /*
97*0Sstevel@tonic-gate  * Unlink a node from the list ... the lock must be held.
98*0Sstevel@tonic-gate  */
99*0Sstevel@tonic-gate static void
np_unlink(struct available * np)100*0Sstevel@tonic-gate np_unlink(struct available *np)
101*0Sstevel@tonic-gate {
102*0Sstevel@tonic-gate 	if (np->prev)
103*0Sstevel@tonic-gate 		np->prev->next = np->next;
104*0Sstevel@tonic-gate 	else
105*0Sstevel@tonic-gate 		nhead = np->next;
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate 	if (np->next)
108*0Sstevel@tonic-gate 		np->next->prev = np->prev;
109*0Sstevel@tonic-gate }
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate /*
112*0Sstevel@tonic-gate  * Insert fp before np ... the lock must be held.
113*0Sstevel@tonic-gate  */
114*0Sstevel@tonic-gate static void
np_insert(struct available * fp,struct available * np)115*0Sstevel@tonic-gate np_insert(struct available *fp, struct available *np)
116*0Sstevel@tonic-gate {
117*0Sstevel@tonic-gate 	fp->prev = np->prev;
118*0Sstevel@tonic-gate 	fp->next = np;
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate 	if (np->prev)
121*0Sstevel@tonic-gate 		np->prev->next = fp;
122*0Sstevel@tonic-gate 	else
123*0Sstevel@tonic-gate 		nhead = fp;
124*0Sstevel@tonic-gate 	np->prev = fp;
125*0Sstevel@tonic-gate }
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate /*
128*0Sstevel@tonic-gate  * Add fp to the end of the list ... the lock must be held.
129*0Sstevel@tonic-gate  */
130*0Sstevel@tonic-gate static void
np_add(struct available * fp)131*0Sstevel@tonic-gate np_add(struct available *fp)
132*0Sstevel@tonic-gate {
133*0Sstevel@tonic-gate 	struct available *np;
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate 	if (nhead == NULL) {
136*0Sstevel@tonic-gate 		nhead = fp;
137*0Sstevel@tonic-gate 		return;
138*0Sstevel@tonic-gate 	}
139*0Sstevel@tonic-gate 
140*0Sstevel@tonic-gate 	for (np = nhead; np->next != NULL; np = np->next)
141*0Sstevel@tonic-gate 		/* empty */;
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate 	np->next = fp;
144*0Sstevel@tonic-gate 	fp->prev = np;
145*0Sstevel@tonic-gate }
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate /*
148*0Sstevel@tonic-gate  * If this entry and the next entry are consecutive, coalesce the
149*0Sstevel@tonic-gate  * two entries into a single entry ... the lock must be held.
150*0Sstevel@tonic-gate  * If the entry can be coalesced, the extra entry is freed.
151*0Sstevel@tonic-gate  */
152*0Sstevel@tonic-gate static void
np_coalesce(struct available * np)153*0Sstevel@tonic-gate np_coalesce(struct available *np)
154*0Sstevel@tonic-gate {
155*0Sstevel@tonic-gate 	struct available *xp;
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate 	xp = np->next;
158*0Sstevel@tonic-gate 	if (xp == NULL)
159*0Sstevel@tonic-gate 		return;
160*0Sstevel@tonic-gate 
161*0Sstevel@tonic-gate 	if ((np->nodeid + np->count) == xp->nodeid) {
162*0Sstevel@tonic-gate 		np->count += xp->count;
163*0Sstevel@tonic-gate 		np_unlink(xp);
164*0Sstevel@tonic-gate 		np_free(xp);
165*0Sstevel@tonic-gate 	}
166*0Sstevel@tonic-gate }
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate void
impl_ddi_init_nodeid(void)169*0Sstevel@tonic-gate impl_ddi_init_nodeid(void)
170*0Sstevel@tonic-gate {
171*0Sstevel@tonic-gate 	struct available *np;
172*0Sstevel@tonic-gate 
173*0Sstevel@tonic-gate 	mutex_init(&nodeid_lock, NULL, MUTEX_DEFAULT, NULL);
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate 	/*
176*0Sstevel@tonic-gate 	 * Copy the seed into kmem_alloc-ed memory so we don't have to
177*0Sstevel@tonic-gate 	 * worry about not freeing it later.
178*0Sstevel@tonic-gate 	 */
179*0Sstevel@tonic-gate 	np = np_alloc(KM_SLEEP);
180*0Sstevel@tonic-gate 	*np = seed;
181*0Sstevel@tonic-gate 	nhead = np;
182*0Sstevel@tonic-gate }
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate int
impl_ddi_alloc_nodeid(int * nodeid)185*0Sstevel@tonic-gate impl_ddi_alloc_nodeid(int *nodeid)
186*0Sstevel@tonic-gate {
187*0Sstevel@tonic-gate 	struct available *np;
188*0Sstevel@tonic-gate 	int x;
189*0Sstevel@tonic-gate 	int unlinked = 0;
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate 	mutex_enter(&nodeid_lock);
192*0Sstevel@tonic-gate 
193*0Sstevel@tonic-gate 	if (nhead == NULL) {
194*0Sstevel@tonic-gate 		mutex_exit(&nodeid_lock);
195*0Sstevel@tonic-gate 		*nodeid = 0;
196*0Sstevel@tonic-gate 		return (DDI_FAILURE);
197*0Sstevel@tonic-gate 	}
198*0Sstevel@tonic-gate 
199*0Sstevel@tonic-gate 	np = nhead;
200*0Sstevel@tonic-gate 	x = (int)((unsigned int)np->nodeid);
201*0Sstevel@tonic-gate 	++np->nodeid;
202*0Sstevel@tonic-gate 	--np->count;
203*0Sstevel@tonic-gate 	if (np->count == 0) {
204*0Sstevel@tonic-gate 		np_unlink(np);
205*0Sstevel@tonic-gate 		unlinked = 1;
206*0Sstevel@tonic-gate 	}
207*0Sstevel@tonic-gate 	mutex_exit(&nodeid_lock);
208*0Sstevel@tonic-gate 
209*0Sstevel@tonic-gate 	if (unlinked)
210*0Sstevel@tonic-gate 		np_free(np);
211*0Sstevel@tonic-gate 
212*0Sstevel@tonic-gate 	ASSERT(x != 0);
213*0Sstevel@tonic-gate 	ASSERT(x != DEVI_PSEUDO_NODEID);
214*0Sstevel@tonic-gate 	ASSERT(x != DEVI_SID_NODEID);
215*0Sstevel@tonic-gate 
216*0Sstevel@tonic-gate 	*nodeid = x;
217*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
218*0Sstevel@tonic-gate }
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate void
impl_ddi_free_nodeid(int n)221*0Sstevel@tonic-gate impl_ddi_free_nodeid(int n)
222*0Sstevel@tonic-gate {
223*0Sstevel@tonic-gate 	uint32_t nodeid = (uint32_t)n;
224*0Sstevel@tonic-gate 	struct available *np, *fp;
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate 	ASSERT(n != 0);
227*0Sstevel@tonic-gate 	ASSERT(n != DEVI_PSEUDO_NODEID);
228*0Sstevel@tonic-gate 	ASSERT(n != DEVI_SID_NODEID);
229*0Sstevel@tonic-gate 
230*0Sstevel@tonic-gate 	/*
231*0Sstevel@tonic-gate 	 * Allocate memory wihout holding the lock in case we need it.
232*0Sstevel@tonic-gate 	 * If we don't use it, we'll free it.
233*0Sstevel@tonic-gate 	 */
234*0Sstevel@tonic-gate 	fp = np_alloc(KM_SLEEP);
235*0Sstevel@tonic-gate 
236*0Sstevel@tonic-gate 	mutex_enter(&nodeid_lock);
237*0Sstevel@tonic-gate 
238*0Sstevel@tonic-gate 	/*
239*0Sstevel@tonic-gate 	 * Insert nodeid in the appropriate place in our sorted available
240*0Sstevel@tonic-gate 	 * list. Maintain the list as we do it.
241*0Sstevel@tonic-gate 	 */
242*0Sstevel@tonic-gate 	for (np = nhead; np != NULL; np = np->next) {
243*0Sstevel@tonic-gate 		/*
244*0Sstevel@tonic-gate 		 * Add to the beginning of this entry?
245*0Sstevel@tonic-gate 		 */
246*0Sstevel@tonic-gate 		if ((nodeid + 1) == np->nodeid) {
247*0Sstevel@tonic-gate 			np->nodeid = nodeid;
248*0Sstevel@tonic-gate 			++np->count;
249*0Sstevel@tonic-gate 			mutex_exit(&nodeid_lock);
250*0Sstevel@tonic-gate 			np_free(fp);
251*0Sstevel@tonic-gate 			return;
252*0Sstevel@tonic-gate 		}
253*0Sstevel@tonic-gate 		/*
254*0Sstevel@tonic-gate 		 * Add to end of this entry? (If yes, try to coalesce
255*0Sstevel@tonic-gate 		 * this entry with the next entry.)
256*0Sstevel@tonic-gate 		 */
257*0Sstevel@tonic-gate 		if (nodeid == (np->nodeid + np->count)) {
258*0Sstevel@tonic-gate 			++np->count;
259*0Sstevel@tonic-gate 			np_coalesce(np);
260*0Sstevel@tonic-gate 			mutex_exit(&nodeid_lock);
261*0Sstevel@tonic-gate 			np_free(fp);
262*0Sstevel@tonic-gate 			return;
263*0Sstevel@tonic-gate 		}
264*0Sstevel@tonic-gate 		/*
265*0Sstevel@tonic-gate 		 * Does it belong before this entry? (new entry)
266*0Sstevel@tonic-gate 		 */
267*0Sstevel@tonic-gate 		if (nodeid < np->nodeid)  {
268*0Sstevel@tonic-gate 			fp->nodeid = nodeid;
269*0Sstevel@tonic-gate 			fp->count = 1;
270*0Sstevel@tonic-gate 			np_insert(fp, np);
271*0Sstevel@tonic-gate 			mutex_exit(&nodeid_lock);
272*0Sstevel@tonic-gate 			return;
273*0Sstevel@tonic-gate 		}
274*0Sstevel@tonic-gate 		if (nodeid < (np->nodeid + np->count))
275*0Sstevel@tonic-gate 			cmn_err(CE_PANIC, "impl_ddi_free_nodeid: "
276*0Sstevel@tonic-gate 			    "nodeid %x already free", n);
277*0Sstevel@tonic-gate 	}
278*0Sstevel@tonic-gate 
279*0Sstevel@tonic-gate 	/*
280*0Sstevel@tonic-gate 	 * Add a new list item to the end of the list ...
281*0Sstevel@tonic-gate 	 */
282*0Sstevel@tonic-gate 	fp->nodeid = nodeid;
283*0Sstevel@tonic-gate 	fp->count = 1;
284*0Sstevel@tonic-gate 	np_add(fp);
285*0Sstevel@tonic-gate 	mutex_exit(&nodeid_lock);
286*0Sstevel@tonic-gate }
287*0Sstevel@tonic-gate 
288*0Sstevel@tonic-gate /*
289*0Sstevel@tonic-gate  * Remove (take) nodeid n off of the available list.
290*0Sstevel@tonic-gate  * Returns 0 if successful or -1 if it fails.
291*0Sstevel@tonic-gate  *
292*0Sstevel@tonic-gate  * A failure indicates we were called with KM_NOSLEEP and we
293*0Sstevel@tonic-gate  * couldn't allocate memory when we needed to.
294*0Sstevel@tonic-gate  */
295*0Sstevel@tonic-gate int
impl_ddi_take_nodeid(int n,int kmflag)296*0Sstevel@tonic-gate impl_ddi_take_nodeid(int n, int kmflag)
297*0Sstevel@tonic-gate {
298*0Sstevel@tonic-gate 	uint32_t nodeid = (uint32_t)n;
299*0Sstevel@tonic-gate 	struct available *np, *fp;
300*0Sstevel@tonic-gate 	int unlinked = 0;
301*0Sstevel@tonic-gate 
302*0Sstevel@tonic-gate 	ASSERT(n != 0);
303*0Sstevel@tonic-gate 	ASSERT(n != DEVI_PSEUDO_NODEID);
304*0Sstevel@tonic-gate 	ASSERT(n != DEVI_SID_NODEID);
305*0Sstevel@tonic-gate 
306*0Sstevel@tonic-gate 	/*
307*0Sstevel@tonic-gate 	 * If this nodeid is not within the range of nodeids we
308*0Sstevel@tonic-gate 	 * manage, we simply succeed.  The initial seed may be
309*0Sstevel@tonic-gate 	 * setup so that promif nodeids fall outside our range.
310*0Sstevel@tonic-gate 	 */
311*0Sstevel@tonic-gate 	if ((nodeid < OUR_NODEID_MIN) || (nodeid > OUR_NODEID_MAX))
312*0Sstevel@tonic-gate 		return (0);
313*0Sstevel@tonic-gate 
314*0Sstevel@tonic-gate 	/*
315*0Sstevel@tonic-gate 	 * Allocate memory wihout holding the lock in case we need it.
316*0Sstevel@tonic-gate 	 * If we don't use it, we'll free it.
317*0Sstevel@tonic-gate 	 */
318*0Sstevel@tonic-gate 	fp = np_alloc(kmflag);		/* if KM_NOSLEEP, fp may be NULL */
319*0Sstevel@tonic-gate 
320*0Sstevel@tonic-gate 	mutex_enter(&nodeid_lock);
321*0Sstevel@tonic-gate 
322*0Sstevel@tonic-gate 	/*
323*0Sstevel@tonic-gate 	 * Find nodeid in our list, if it exists, 'take' it.
324*0Sstevel@tonic-gate 	 */
325*0Sstevel@tonic-gate 	for (np = nhead; np != NULL; np = np->next) {
326*0Sstevel@tonic-gate 
327*0Sstevel@tonic-gate 		/*
328*0Sstevel@tonic-gate 		 * If it's less than this entry, it's not available...
329*0Sstevel@tonic-gate 		 */
330*0Sstevel@tonic-gate 		if (nodeid < np->nodeid)
331*0Sstevel@tonic-gate 			break;
332*0Sstevel@tonic-gate 
333*0Sstevel@tonic-gate 		/*
334*0Sstevel@tonic-gate 		 * If it's the first entry in this list item, take it ...
335*0Sstevel@tonic-gate 		 */
336*0Sstevel@tonic-gate 		if ((nodeid) == np->nodeid) {
337*0Sstevel@tonic-gate 			++np->nodeid;
338*0Sstevel@tonic-gate 			--np->count;
339*0Sstevel@tonic-gate 			if (np->count == 0) {
340*0Sstevel@tonic-gate 				np_unlink(np);
341*0Sstevel@tonic-gate 				++unlinked;
342*0Sstevel@tonic-gate 			}
343*0Sstevel@tonic-gate 			mutex_exit(&nodeid_lock);
344*0Sstevel@tonic-gate 			if (fp)
345*0Sstevel@tonic-gate 				np_free(fp);
346*0Sstevel@tonic-gate 			if (unlinked)
347*0Sstevel@tonic-gate 				np_free(np);
348*0Sstevel@tonic-gate 			return (0);
349*0Sstevel@tonic-gate 		}
350*0Sstevel@tonic-gate 
351*0Sstevel@tonic-gate 		/*
352*0Sstevel@tonic-gate 		 * If it's the last entry in this list item, take it ...
353*0Sstevel@tonic-gate 		 * The count can't be 1 otherwise it would have matched
354*0Sstevel@tonic-gate 		 * the beginning of list case, above.
355*0Sstevel@tonic-gate 		 */
356*0Sstevel@tonic-gate 		if (nodeid == (np->nodeid + np->count - 1)) {
357*0Sstevel@tonic-gate 			--np->count;
358*0Sstevel@tonic-gate 			ASSERT(np->count != 0);
359*0Sstevel@tonic-gate 			mutex_exit(&nodeid_lock);
360*0Sstevel@tonic-gate 			if (fp)
361*0Sstevel@tonic-gate 				np_free(fp);
362*0Sstevel@tonic-gate 			return (0);
363*0Sstevel@tonic-gate 		}
364*0Sstevel@tonic-gate 
365*0Sstevel@tonic-gate 		/*
366*0Sstevel@tonic-gate 		 * Is it in the middle of this entry? If it is, we'll
367*0Sstevel@tonic-gate 		 * have to split np into two items, removing nodeid
368*0Sstevel@tonic-gate 		 * from the middle of the list item.
369*0Sstevel@tonic-gate 		 */
370*0Sstevel@tonic-gate 		if (nodeid < (np->nodeid + np->count - 1)) {
371*0Sstevel@tonic-gate 			if (fp == NULL) {
372*0Sstevel@tonic-gate 				/*
373*0Sstevel@tonic-gate 				 * We were called with KM_NOSLEEP and
374*0Sstevel@tonic-gate 				 * were unable to allocate memory.
375*0Sstevel@tonic-gate 				 */
376*0Sstevel@tonic-gate 				mutex_exit(&nodeid_lock);
377*0Sstevel@tonic-gate 				return (-1);
378*0Sstevel@tonic-gate 			}
379*0Sstevel@tonic-gate 			/*
380*0Sstevel@tonic-gate 			 * Split np, removing nodeid from the middle of
381*0Sstevel@tonic-gate 			 * this entry. We already know it isn't on either
382*0Sstevel@tonic-gate 			 * end of of this entry, so we know we have to split it.
383*0Sstevel@tonic-gate 			 */
384*0Sstevel@tonic-gate 			fp->nodeid = np->nodeid;
385*0Sstevel@tonic-gate 			fp->count = nodeid - np->nodeid;
386*0Sstevel@tonic-gate 			np->nodeid = nodeid + 1;
387*0Sstevel@tonic-gate 			np->count = np->count - fp->count - 1;
388*0Sstevel@tonic-gate 			ASSERT((fp->count != 0) && (np->count != 0));
389*0Sstevel@tonic-gate 			ASSERT(np->nodeid == (fp->nodeid + fp->count + 1));
390*0Sstevel@tonic-gate 			np_insert(fp, np);
391*0Sstevel@tonic-gate 			mutex_exit(&nodeid_lock);
392*0Sstevel@tonic-gate 			return (0);
393*0Sstevel@tonic-gate 		}
394*0Sstevel@tonic-gate 	}
395*0Sstevel@tonic-gate 
396*0Sstevel@tonic-gate 	/*
397*0Sstevel@tonic-gate 	 * Apparently the nodeid is not available ...
398*0Sstevel@tonic-gate 	 */
399*0Sstevel@tonic-gate 	mutex_exit(&nodeid_lock);
400*0Sstevel@tonic-gate 
401*0Sstevel@tonic-gate 	if (fp)
402*0Sstevel@tonic-gate 		np_free(fp);
403*0Sstevel@tonic-gate 	cmn_err(CE_CONT, "?impl_ddi_take_nodeid: nodeid %x may not "
404*0Sstevel@tonic-gate 	    "be unique\n", nodeid);
405*0Sstevel@tonic-gate 	return (0);
406*0Sstevel@tonic-gate }
407