xref: /illumos-gate/usr/src/uts/common/sys/ddi_ufm_impl.h (revision f52943a93040563107b95bccb9db87d9971ef47d)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2019 Joyent, Inc.
14  */
15 
16 #ifndef _SYS_DDI_UFM_IMPL_H
17 #define	_SYS_DDI_UFM_IMPL_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #include <sys/avl.h>
24 #include <sys/ddi_ufm.h>
25 #include <sys/mutex.h>
26 #include <sys/nvpair.h>
27 #include <sys/types.h>
28 
29 typedef enum {
30 	DDI_UFM_STATE_INIT		= 1 << 0,
31 	DDI_UFM_STATE_READY		= 1 << 1,
32 	DDI_UFM_STATE_SHUTTING_DOWN	= 1 << 2
33 } ddi_ufm_state_t;
34 
35 /* private interface for startup_ddi() */
36 void ufm_init();
37 
38 /* private interfaces for ufm driver */
39 struct ddi_ufm_handle *ufm_find(const char *);
40 int ufm_cache_fill(struct ddi_ufm_handle *ufmh);
41 
42 struct ddi_ufm_slot {
43 	uint_t			ufms_slotno;
44 	char			*ufms_version;
45 	ddi_ufm_attr_t		ufms_attrs;
46 	nvlist_t		*ufms_misc;
47 };
48 
49 struct ddi_ufm_image {
50 	uint_t			ufmi_imageno;
51 	char			*ufmi_desc;
52 	nvlist_t		*ufmi_misc;
53 	struct ddi_ufm_slot	*ufmi_slots;
54 	uint_t			ufmi_nslots;
55 };
56 
57 struct ddi_ufm_handle {
58 	/*
59 	 * The following fields get filled in when a UFM-aware driver calls
60 	 * ddi_ufm_init(9E).  They remain valid until the driver calls
61 	 * ddi_ufm_fini(9E).  You can test for validity of these fields by
62 	 * checking if the DDI_UFM_STATE_INIT flag is set in ufmh_state.
63 	 */
64 	kmutex_t		ufmh_lock;
65 	char			ufmh_devpath[MAXPATHLEN];
66 	ddi_ufm_ops_t		*ufmh_ops;
67 	void			*ufmh_arg;
68 	uint_t			ufmh_state;
69 	uint_t			ufmh_version;
70 	/*
71 	 * The following four fields represent lazily cached UFM data
72 	 * retrieved from a UFM-aware driver.  If ufmh_report is non-NULL
73 	 * then all four of these fields will contain valid data.
74 	 */
75 	struct ddi_ufm_image	*ufmh_images;
76 	uint_t			ufmh_nimages;
77 	ddi_ufm_cap_t		ufmh_caps;
78 	nvlist_t		*ufmh_report;
79 
80 	avl_node_t		ufmh_link;
81 };
82 
83 #ifdef __cplusplus
84 }
85 #endif
86 
87 #endif	/* _SYS_DDI_UFM_IMPL_H */
88