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