xref: /illumos-gate/usr/src/uts/common/sys/gpio/kgpio.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 _SYS_GPIO_KGPIO_H
17 #define	_SYS_GPIO_KGPIO_H
18 
19 /*
20  * User / Kernel kgpio interface
21  */
22 
23 #include <sys/stdint.h>
24 #include <sys/param.h>
25 #include <sys/gpio/kgpio_attr.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #define	KGPIO_IOC	(('k' << 24) | ('g' << 16) | ('p' << 8))
32 
33 /*
34  * Obtain basic information about a GPIO controller.
35  */
36 #define	KGPIO_IOC_CTRL_INFO	(KGPIO_IOC | 1)
37 typedef struct {
38 	uint32_t	kci_ngroups;
39 	uint32_t	kci_ngpios;
40 	uint32_t	kci_ndpios;
41 	uint32_t	kci_pad;
42 	char		kci_devpath[MAXPATHLEN];
43 } kgpio_ctrl_info_t;
44 
45 /*
46  * This gets detailed information about a given GPIO. It includes all the
47  * provider's attributes as well for the GPIO.
48  */
49 #define	KGPIO_IOC_GPIO_INFO	(KGPIO_IOC | 2)
50 
51 typedef enum {
52 	KGPIO_GPIO_F_DPIO	= 1 << 0
53 } kgpio_gpio_flags_t;
54 
55 typedef struct {
56 	uint32_t		kgi_id;
57 	kgpio_gpio_flags_t	kgi_flags;
58 	uintptr_t		kgi_attr;
59 	size_t			kgi_attr_len;
60 } kgpio_gpio_info_t;
61 
62 /*
63  * This is used to set the attributes of a given GPIO. It takes an nvlist_t and
64  * also returns an nvlist_t of errors.
65  */
66 #define	KGPIO_IOC_GPIO_UPDATE	(KGPIO_IOC | 3)
67 
68 typedef enum {
69 	/*
70 	 * This flag is set by the kernel on return. If the system returns 0,
71 	 * then this must be checked to see if there were errors available.
72 	 */
73 	KGPIO_UPDATE_ERROR = 1 << 0,
74 	/*
75 	 * Indicates that the information in the error NVL is valid.
76 	 */
77 	KGPIO_UPDATE_ERR_NVL_VALID = 1 << 1
78 } kgpio_update_flags_t;
79 
80 typedef struct {
81 	uint32_t		kgu_id;
82 	kgpio_update_flags_t	kgu_flags;
83 	uintptr_t		kgu_attr;
84 	size_t			kgu_attr_len;
85 	uintptr_t		kgu_err;
86 	size_t			kgu_err_len;
87 } kgpio_update_t;
88 
89 /*
90  * This is used to create a DPIO from a given GPIO.
91  */
92 #define	KGPIO_IOC_DPIO_CREATE	(KGPIO_IOC | 4)
93 
94 typedef enum {
95 	/*
96 	 * Indicates that reading the input value of the DPIO is allowed.
97 	 */
98 	KGPIO_DPIO_F_READ	= 1 << 0,
99 	/*
100 	 * Indicates that setting the output value of the DPIO is allowed.
101 	 */
102 	KGPIO_DPIO_F_WRITE	= 1 << 1,
103 	/*
104 	 * Indicates that the DPIO should be restricted to only the kernel.
105 	 */
106 	KGPIO_DPIO_F_KERNEL	= 1 << 2
107 } kgpio_dpio_flags_t;
108 
109 #define	KGPIO_DPIO_NAMELEN	32
110 
111 typedef struct {
112 	uint32_t		kdc_id;
113 	kgpio_dpio_flags_t	kdc_flags;
114 	char			kdc_name[KGPIO_DPIO_NAMELEN];
115 } kgpio_dpio_create_t;
116 
117 /*
118  * This is used to destroy a DPIO that is bound to the specific GPIO.
119  */
120 #define	KGPIO_IOC_DPIO_DESTROY	(KGPIO_IOC | 5)
121 typedef struct {
122 	uint32_t	kdd_id;
123 	uint32_t	kdd_pad;
124 } kgpio_dpio_destroy_t;
125 
126 /*
127  * Determines if a GPIO with the specified name is present on the given
128  * controller. If so, its ID is returned.
129  */
130 #define	KGPIO_IOC_GPIO_NAME2ID	(KGPIO_IOC | 6)
131 typedef struct {
132 	char		kin_name[MAXPATHLEN];
133 	uint32_t	kin_id;
134 } kgpio_ioc_name2id_t;
135 
136 /*
137  * Kernel-specific views for 32-bit.
138  */
139 #ifdef	_KERNEL
140 typedef struct {
141 	uint32_t		kgi_id;
142 	kgpio_gpio_flags_t	kgi_flags;
143 	uintptr32_t		kgi_attr;
144 	size32_t		kgi_attr_len;
145 } kgpio_gpio_info32_t;
146 
147 typedef struct {
148 	uint32_t		kgu_id;
149 	kgpio_update_flags_t	kgu_flags;
150 	uintptr32_t		kgu_attr;
151 	size32_t		kgu_attr_len;
152 	uintptr32_t		kgu_err;
153 	size32_t		kgu_err_len;
154 } kgpio_update32_t;
155 #endif	/* _KERNEL */
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif /* _SYS_GPIO_KGPIO_H */
162