xref: /netbsd/sys/dev/raidframe/rf_callback.c (revision bf9ec67e)
1 /*	$NetBSD: rf_callback.c,v 1.6 2001/11/13 07:11:12 lukem Exp $	*/
2 /*
3  * Copyright (c) 1995 Carnegie-Mellon University.
4  * All rights reserved.
5  *
6  * Author: Jim Zelenka
7  *
8  * Permission to use, copy, modify and distribute this software and
9  * its documentation is hereby granted, provided that both the copyright
10  * notice and this permission notice appear in all copies of the
11  * software, derivative works or modified versions, and any portions
12  * thereof, and that both notices appear in supporting documentation.
13  *
14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17  *
18  * Carnegie Mellon requests users of this software to return to
19  *
20  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
21  *  School of Computer Science
22  *  Carnegie Mellon University
23  *  Pittsburgh PA 15213-3890
24  *
25  * any improvements or extensions that they make and grant Carnegie the
26  * rights to redistribute these changes.
27  */
28 
29 /*****************************************************************************************
30  *
31  * callback.c -- code to manipulate callback descriptor
32  *
33  ****************************************************************************************/
34 
35 
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: rf_callback.c,v 1.6 2001/11/13 07:11:12 lukem Exp $");
38 
39 #include <dev/raidframe/raidframevar.h>
40 
41 #include "rf_archs.h"
42 #include "rf_threadstuff.h"
43 #include "rf_callback.h"
44 #include "rf_debugMem.h"
45 #include "rf_freelist.h"
46 #include "rf_shutdown.h"
47 
48 static RF_FreeList_t *rf_callback_freelist;
49 
50 #define RF_MAX_FREE_CALLBACK 64
51 #define RF_CALLBACK_INC       4
52 #define RF_CALLBACK_INITIAL   4
53 
54 static void rf_ShutdownCallback(void *);
55 static void
56 rf_ShutdownCallback(ignored)
57 	void   *ignored;
58 {
59 	RF_FREELIST_DESTROY(rf_callback_freelist, next, (RF_CallbackDesc_t *));
60 }
61 
62 int
63 rf_ConfigureCallback(listp)
64 	RF_ShutdownList_t **listp;
65 {
66 	int     rc;
67 
68 	RF_FREELIST_CREATE(rf_callback_freelist, RF_MAX_FREE_CALLBACK,
69 	    RF_CALLBACK_INC, sizeof(RF_CallbackDesc_t));
70 	if (rf_callback_freelist == NULL)
71 		return (ENOMEM);
72 	rc = rf_ShutdownCreate(listp, rf_ShutdownCallback, NULL);
73 	if (rc) {
74 		RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n", __FILE__,
75 		    __LINE__, rc);
76 		rf_ShutdownCallback(NULL);
77 		return (rc);
78 	}
79 	RF_FREELIST_PRIME(rf_callback_freelist, RF_CALLBACK_INITIAL, next,
80 	    (RF_CallbackDesc_t *));
81 	return (0);
82 }
83 
84 RF_CallbackDesc_t *
85 rf_AllocCallbackDesc()
86 {
87 	RF_CallbackDesc_t *p;
88 
89 	RF_FREELIST_GET(rf_callback_freelist, p, next, (RF_CallbackDesc_t *));
90 	return (p);
91 }
92 
93 void
94 rf_FreeCallbackDesc(p)
95 	RF_CallbackDesc_t *p;
96 {
97 	RF_FREELIST_FREE(rf_callback_freelist, p, next);
98 }
99