1508a0e8cSRob Johnston /*
2508a0e8cSRob Johnston  * This file and its contents are supplied under the terms of the
3508a0e8cSRob Johnston  * Common Development and Distribution License ("CDDL"), version 1.0.
4508a0e8cSRob Johnston  * You may only use this file in accordance with the terms of version
5508a0e8cSRob Johnston  * 1.0 of the CDDL.
6508a0e8cSRob Johnston  *
7508a0e8cSRob Johnston  * A full copy of the text of the CDDL should have accompanied this
8508a0e8cSRob Johnston  * source.  A copy of the CDDL is also available via the Internet at
9508a0e8cSRob Johnston  * http://www.illumos.org/license/CDDL.
10508a0e8cSRob Johnston  */
11508a0e8cSRob Johnston 
12508a0e8cSRob Johnston /*
13508a0e8cSRob Johnston  * Copyright 2019 Joyent, Inc.
14*8d55b806SRobert Mustacchi  * Copyright 2020 Oxide Computer Company
15508a0e8cSRob Johnston  */
16508a0e8cSRob Johnston 
17508a0e8cSRob Johnston #ifndef _SYS_DDI_UFM_IMPL_H
18508a0e8cSRob Johnston #define	_SYS_DDI_UFM_IMPL_H
19508a0e8cSRob Johnston 
20508a0e8cSRob Johnston #ifdef __cplusplus
21508a0e8cSRob Johnston extern "C" {
22508a0e8cSRob Johnston #endif
23508a0e8cSRob Johnston 
24508a0e8cSRob Johnston #include <sys/avl.h>
25508a0e8cSRob Johnston #include <sys/ddi_ufm.h>
26508a0e8cSRob Johnston #include <sys/mutex.h>
27508a0e8cSRob Johnston #include <sys/nvpair.h>
28508a0e8cSRob Johnston #include <sys/types.h>
29508a0e8cSRob Johnston 
30508a0e8cSRob Johnston typedef enum {
31508a0e8cSRob Johnston 	DDI_UFM_STATE_INIT		= 1 << 0,
32508a0e8cSRob Johnston 	DDI_UFM_STATE_READY		= 1 << 1,
33508a0e8cSRob Johnston 	DDI_UFM_STATE_SHUTTING_DOWN	= 1 << 2
34508a0e8cSRob Johnston } ddi_ufm_state_t;
35508a0e8cSRob Johnston 
36508a0e8cSRob Johnston /* private interface for startup_ddi() */
37508a0e8cSRob Johnston void ufm_init();
38508a0e8cSRob Johnston 
39508a0e8cSRob Johnston /* private interfaces for ufm driver */
40508a0e8cSRob Johnston struct ddi_ufm_handle *ufm_find(const char *);
41508a0e8cSRob Johnston int ufm_cache_fill(struct ddi_ufm_handle *ufmh);
42*8d55b806SRobert Mustacchi int ufm_read_img(ddi_ufm_handle_t *, uint_t, uint_t, uint64_t, uint64_t,
43*8d55b806SRobert Mustacchi     uintptr_t, uint64_t *, int);
44508a0e8cSRob Johnston 
45508a0e8cSRob Johnston struct ddi_ufm_slot {
46508a0e8cSRob Johnston 	uint_t			ufms_slotno;
47508a0e8cSRob Johnston 	char			*ufms_version;
48508a0e8cSRob Johnston 	ddi_ufm_attr_t		ufms_attrs;
49*8d55b806SRobert Mustacchi 	uint64_t		ufms_imgsize;
50508a0e8cSRob Johnston 	nvlist_t		*ufms_misc;
51508a0e8cSRob Johnston };
52508a0e8cSRob Johnston 
53508a0e8cSRob Johnston struct ddi_ufm_image {
54508a0e8cSRob Johnston 	uint_t			ufmi_imageno;
55508a0e8cSRob Johnston 	char			*ufmi_desc;
56508a0e8cSRob Johnston 	nvlist_t		*ufmi_misc;
57508a0e8cSRob Johnston 	struct ddi_ufm_slot	*ufmi_slots;
58508a0e8cSRob Johnston 	uint_t			ufmi_nslots;
59508a0e8cSRob Johnston };
60508a0e8cSRob Johnston 
61508a0e8cSRob Johnston struct ddi_ufm_handle {
62508a0e8cSRob Johnston 	/*
63508a0e8cSRob Johnston 	 * The following fields get filled in when a UFM-aware driver calls
64508a0e8cSRob Johnston 	 * ddi_ufm_init(9E).  They remain valid until the driver calls
65508a0e8cSRob Johnston 	 * ddi_ufm_fini(9E).  You can test for validity of these fields by
66508a0e8cSRob Johnston 	 * checking if the DDI_UFM_STATE_INIT flag is set in ufmh_state.
67508a0e8cSRob Johnston 	 */
68508a0e8cSRob Johnston 	kmutex_t		ufmh_lock;
69508a0e8cSRob Johnston 	char			ufmh_devpath[MAXPATHLEN];
70508a0e8cSRob Johnston 	ddi_ufm_ops_t		*ufmh_ops;
71508a0e8cSRob Johnston 	void			*ufmh_arg;
72508a0e8cSRob Johnston 	uint_t			ufmh_state;
73508a0e8cSRob Johnston 	uint_t			ufmh_version;
74508a0e8cSRob Johnston 	/*
75508a0e8cSRob Johnston 	 * The following four fields represent lazily cached UFM data
76508a0e8cSRob Johnston 	 * retrieved from a UFM-aware driver.  If ufmh_report is non-NULL
77508a0e8cSRob Johnston 	 * then all four of these fields will contain valid data.
78508a0e8cSRob Johnston 	 */
79508a0e8cSRob Johnston 	struct ddi_ufm_image	*ufmh_images;
80508a0e8cSRob Johnston 	uint_t			ufmh_nimages;
81508a0e8cSRob Johnston 	ddi_ufm_cap_t		ufmh_caps;
82508a0e8cSRob Johnston 	nvlist_t		*ufmh_report;
83508a0e8cSRob Johnston 
84508a0e8cSRob Johnston 	avl_node_t		ufmh_link;
85508a0e8cSRob Johnston };
86508a0e8cSRob Johnston 
87508a0e8cSRob Johnston #ifdef __cplusplus
88508a0e8cSRob Johnston }
89508a0e8cSRob Johnston #endif
90508a0e8cSRob Johnston 
91508a0e8cSRob Johnston #endif	/* _SYS_DDI_UFM_IMPL_H */
92