xref: /illumos-gate/usr/src/uts/common/sys/ddi_ufm_impl.h (revision 8d55b80625b903a8ec6c560f6a38b5c16d1f5cfc)
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  * Copyright 2020 Oxide Computer Company
15  */
16 
17 #ifndef _SYS_DDI_UFM_IMPL_H
18 #define	_SYS_DDI_UFM_IMPL_H
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #include <sys/avl.h>
25 #include <sys/ddi_ufm.h>
26 #include <sys/mutex.h>
27 #include <sys/nvpair.h>
28 #include <sys/types.h>
29 
30 typedef enum {
31 	DDI_UFM_STATE_INIT		= 1 << 0,
32 	DDI_UFM_STATE_READY		= 1 << 1,
33 	DDI_UFM_STATE_SHUTTING_DOWN	= 1 << 2
34 } ddi_ufm_state_t;
35 
36 /* private interface for startup_ddi() */
37 void ufm_init();
38 
39 /* private interfaces for ufm driver */
40 struct ddi_ufm_handle *ufm_find(const char *);
41 int ufm_cache_fill(struct ddi_ufm_handle *ufmh);
42 int ufm_read_img(ddi_ufm_handle_t *, uint_t, uint_t, uint64_t, uint64_t,
43     uintptr_t, uint64_t *, int);
44 
45 struct ddi_ufm_slot {
46 	uint_t			ufms_slotno;
47 	char			*ufms_version;
48 	ddi_ufm_attr_t		ufms_attrs;
49 	uint64_t		ufms_imgsize;
50 	nvlist_t		*ufms_misc;
51 };
52 
53 struct ddi_ufm_image {
54 	uint_t			ufmi_imageno;
55 	char			*ufmi_desc;
56 	nvlist_t		*ufmi_misc;
57 	struct ddi_ufm_slot	*ufmi_slots;
58 	uint_t			ufmi_nslots;
59 };
60 
61 struct ddi_ufm_handle {
62 	/*
63 	 * The following fields get filled in when a UFM-aware driver calls
64 	 * ddi_ufm_init(9E).  They remain valid until the driver calls
65 	 * ddi_ufm_fini(9E).  You can test for validity of these fields by
66 	 * checking if the DDI_UFM_STATE_INIT flag is set in ufmh_state.
67 	 */
68 	kmutex_t		ufmh_lock;
69 	char			ufmh_devpath[MAXPATHLEN];
70 	ddi_ufm_ops_t		*ufmh_ops;
71 	void			*ufmh_arg;
72 	uint_t			ufmh_state;
73 	uint_t			ufmh_version;
74 	/*
75 	 * The following four fields represent lazily cached UFM data
76 	 * retrieved from a UFM-aware driver.  If ufmh_report is non-NULL
77 	 * then all four of these fields will contain valid data.
78 	 */
79 	struct ddi_ufm_image	*ufmh_images;
80 	uint_t			ufmh_nimages;
81 	ddi_ufm_cap_t		ufmh_caps;
82 	nvlist_t		*ufmh_report;
83 
84 	avl_node_t		ufmh_link;
85 };
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 #endif	/* _SYS_DDI_UFM_IMPL_H */
92