xref: /titanic_41/usr/src/lib/librcm/librcm_impl.h (revision 7c2fbfb345896881c631598ee3852ce9ce33fb07)
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  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _LIBRCM_IMPL_H
27 #define	_LIBRCM_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <assert.h>
36 #include <stdio.h>
37 #include <stdarg.h>
38 #include <dlfcn.h>
39 #include <errno.h>
40 #include <fcntl.h>
41 #include <poll.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <strings.h>
45 #include <syslog.h>
46 #include <unistd.h>
47 #include <sys/mman.h>
48 #include <sys/wait.h>
49 #include <sys/types.h>
50 #include <sys/stat.h>
51 #include <sys/param.h>
52 #include <sys/systeminfo.h>
53 #include <librcm.h>
54 
55 /*
56  * This file contains information private to librcm rcm_daemon.
57  */
58 #define	RCM_DAEMON_START	"/usr/lib/rcm/rcm_daemon"
59 #define	RCM_SERVICE_DOOR	"/var/run/rcm_daemon_door"
60 #define	RCM_MODULE_SUFFIX	"_rcm.so"
61 
62 /*
63  * flag fields supported by individual librcm interfaces
64  */
65 #define	RCM_ALLOC_HDL_MASK	(RCM_NOPID)
66 #define	RCM_GET_INFO_MASK	(RCM_INCLUDE_SUBTREE|RCM_INCLUDE_DEPENDENT|\
67 				RCM_DR_OPERATION|RCM_MOD_INFO|RCM_FILESYS)
68 #define	RCM_REGISTER_MASK	(RCM_FILESYS|RCM_REGISTER_DR|\
69 				RCM_REGISTER_EVENT|RCM_REGISTER_CAPACITY)
70 #define	RCM_REQUEST_MASK	(RCM_QUERY|RCM_SCOPE|RCM_FORCE|RCM_FILESYS|\
71 				RCM_QUERY_CANCEL|RCM_RETIRE_REQUEST)
72 #define	RCM_NOTIFY_MASK		(RCM_FILESYS|RCM_RETIRE_NOTIFY)
73 
74 /* event data names */
75 #define	RCM_CMD			"rcm.cmd"
76 #define	RCM_RESULT		"rcm.result"
77 #define	RCM_RESULT_INFO		"rcm.result_info"
78 #define	RCM_RSRCNAMES		"rcm.rsrcnames"
79 #define	RCM_RSRCSTATE		"rcm.rsrcstate"
80 #define	RCM_CLIENT_ID		"rcm.client_id"
81 #define	RCM_CLIENT_INFO		"rcm.client_info"
82 #define	RCM_CLIENT_ERROR	"rcm.client_error"
83 #define	RCM_CLIENT_MODNAME	"rcm.client_modname"
84 #define	RCM_CLIENT_PROPERTIES	"rcm.client_properties"
85 #define	RCM_SEQ_NUM		"rcm.seq_num"
86 #define	RCM_REQUEST_FLAG	"rcm.request_flag"
87 #define	RCM_SUSPEND_INTERVAL	"rcm.suspend_interval"
88 #define	RCM_CHANGE_DATA		"rcm.change_data"
89 #define	RCM_EVENT_DATA		"rcm.event_data"
90 
91 /*
92  * action commands shared by librcm and rcm_daemon
93  */
94 #define	CMD_KNOCK		0
95 #define	CMD_REGISTER		1
96 #define	CMD_UNREGISTER		2
97 #define	CMD_GETINFO		3
98 #define	CMD_SUSPEND		4
99 #define	CMD_RESUME		5
100 #define	CMD_OFFLINE		6
101 #define	CMD_ONLINE		7
102 #define	CMD_REMOVE		8
103 #define	CMD_EVENT		9
104 #define	CMD_REQUEST_CHANGE	10
105 #define	CMD_NOTIFY_CHANGE	11
106 #define	CMD_GETSTATE		12
107 
108 /*
109  * Ops vector for calling directly into daemon from RCM modules
110  */
111 typedef struct {
112 	int	(*librcm_regis)();
113 	int	(*librcm_unregis)();
114 	int	(*librcm_getinfo)();
115 	int	(*librcm_suspend)();
116 	int	(*librcm_resume)();
117 	int	(*librcm_offline)();
118 	int	(*librcm_online)();
119 	int	(*librcm_remove)();
120 	int	(*librcm_request_change)();
121 	int	(*librcm_notify_change)();
122 	int	(*librcm_notify_event)();
123 	int	(*librcm_getstate)();
124 } librcm_ops_t;
125 
126 /*
127  * rcm handle struture
128  */
129 struct rcm_handle {
130 	char		*modname;
131 	pid_t		pid;
132 	int		seq_num;
133 	librcm_ops_t	*lrcm_ops;
134 	struct module	*module;
135 };
136 
137 struct rcm_info {
138 	nvlist_t *info;
139 	struct rcm_info	*next;
140 };
141 
142 /*
143  * module utility routines
144  */
145 char *rcm_module_dir(uint_t);
146 void *rcm_module_open(char *);
147 void rcm_module_close(void *);
148 
149 /*
150  * rcm scripting utility routines
151  */
152 char *rcm_script_dir(uint_t dirnum);
153 char *rcm_dir(uint_t dirnum, int *rcm_script);
154 char *rcm_get_script_dir(char *script_name);
155 int rcm_is_script(char *filename);
156 
157 
158 #ifdef	__cplusplus
159 }
160 #endif
161 
162 #endif /* _LIBRCM_IMPL_H */
163