xref: /illumos-gate/usr/src/uts/common/sys/gpio/kgpio_provider.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_PROVIDER_H
17 #define	_SYS_GPIO_KGPIO_PROVIDER_H
18 
19 /*
20  * This header describes the private interface between the kernel GPIO framework
21  * and GPIO providers.
22  */
23 
24 #include <sys/nvpair.h>
25 #include <sys/stdint.h>
26 
27 #include <sys/gpio/dpio.h>
28 #include <sys/gpio/kgpio_attr.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 
35 /*
36  * The remainder of this header is intended for kernel implementations of the
37  * KGPIO framework.
38  */
39 #ifdef _KERNEL
40 
41 typedef int (*kgpio_name2id_f)(void *, const char *, uint32_t *);
42 typedef int (*kgpio_attr_get_f)(void *, uint32_t, nvlist_t *);
43 typedef int (*kgpio_attr_set_f)(void *, uint32_t, nvlist_t *, nvlist_t *);
44 typedef int (*kgpio_dpio_cap_f)(void *, uint32_t, dpio_caps_t *);
45 typedef int (*kgpio_dpio_input_f)(void *, uint32_t, dpio_input_t *);
46 typedef int (*kgpio_dpio_output_get_f)(void *, uint32_t, dpio_output_t *);
47 typedef int (*kgpio_dpio_output_set_f)(void *, uint32_t, dpio_output_t);
48 
49 typedef struct kgpio_ops {
50 	kgpio_name2id_f		kgo_name2id;
51 	kgpio_attr_get_f	kgo_get;
52 	kgpio_attr_set_f	kgo_set;
53 	kgpio_dpio_cap_f	kgo_cap;
54 	kgpio_dpio_input_f	kgo_input;
55 	kgpio_dpio_output_get_f	kgo_output_state;
56 	kgpio_dpio_output_set_f	kgo_output;
57 } kgpio_ops_t;
58 
59 extern int kgpio_register(dev_info_t *, const kgpio_ops_t *, void *, uint32_t);
60 extern int kgpio_unregister(dev_info_t *);
61 
62 /*
63  * These are convenience functions for filling in information about an
64  * attribute.
65  */
66 extern void kgpio_nvl_attr_fill_u32(nvlist_t *, nvlist_t *, const char *,
67     uint32_t, uint_t, uint32_t *, kgpio_prot_t);
68 extern void kgpio_nvl_attr_fill_str(nvlist_t *, nvlist_t *, const char *,
69     const char *, uint_t, char *const *, kgpio_prot_t);
70 
71 #endif	/* _KERNEL */
72 
73 #ifdef __cplusplus
74 }
75 #endif
76 
77 #endif /* _SYS_GPIO_KGPIO_PROVIDER_H */
78