xref: /illumos-gate/usr/src/lib/libxpio/common/libxpio_impl.h (revision fd71220ba0fafcc9cf5ea0785db206f3f31336e7)
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 2022 Oxide Computer Company
14  */
15 
16 #ifndef _LIBXPIO_IMPL_H
17 #define	_LIBXPIO_IMPL_H
18 
19 /*
20  * Internal implementation pieces of libxpio.
21  */
22 
23 #include <libxpio.h>
24 #include <sys/gpio/kgpio.h>
25 #include <sys/gpio/kgpio_provider.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /*
32  * Maximum size of an internal error message.
33  */
34 #define	XPIO_ERR_LEN	1024
35 
36 /*
37  * Maximum size of an nvlist attribute buffer that we'll alloc right now.
38  */
39 #define	XPIO_NVL_LEN	(16 * 1024)
40 
41 struct xpio {
42 	xpio_err_t xp_err;
43 	int32_t xp_syserr;
44 	char xp_errmsg[XPIO_ERR_LEN];
45 	di_node_t xp_devinfo;
46 };
47 
48 struct xpio_ctrl {
49 	list_node_t xc_link;
50 	xpio_t *xc_xpio;
51 	di_minor_t xc_minor;
52 	const char *xc_name;
53 	int xc_fd;
54 };
55 
56 struct xpio_ctrl_info {
57 	uint32_t xci_ngpios;
58 	uint32_t xci_ndpios;
59 	char xci_devpath[MAXPATHLEN];
60 };
61 
62 struct xpio_gpio_info {
63 	uint32_t xgi_id;
64 	kgpio_gpio_flags_t xgi_flags;
65 	nvlist_t *xgi_nvl;
66 };
67 
68 struct xpio_gpio_update {
69 	xpio_update_err_t xgo_err;
70 	int32_t xgo_syserr;
71 	char xgo_errmsg[XPIO_ERR_LEN];
72 	xpio_gpio_info_t *xgo_gpio;
73 	nvlist_t *xgo_update;
74 	nvlist_t *xgo_err_nvl;
75 };
76 
77 struct xpio_dpio_info {
78 	char xdi_dpio[DPIO_NAMELEN];
79 	char xdi_ctrl[DPIO_NAMELEN];
80 	uint32_t xdi_gpio;
81 	dpio_caps_t xdi_caps;
82 	dpio_flags_t xdi_flags;
83 };
84 
85 extern bool xpio_error(xpio_t *, xpio_err_t, int32_t, const char *,
86     ...)  __PRINTFLIKE(4);
87 extern bool xpio_success(xpio_t *);
88 extern bool xpio_update_error(xpio_gpio_update_t *, xpio_update_err_t, int32_t,
89     const char *, ...)  __PRINTFLIKE(4);
90 extern bool xpio_update_success(xpio_gpio_update_t *);
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 
96 #endif /* _LIBXPIO_IMPL_H */
97