xref: /illumos-gate/usr/src/uts/common/sys/gpio/kgpio_attr.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_ATTR_H
17 #define	_SYS_GPIO_KGPIO_ATTR_H
18 
19 /*
20  * This file contains the shared definitions that are useful for understanding
21  * attributes. This includes both the shared fields and required attributes as
22  * well as more advanced error codes related to attributes.
23  */
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /*
30  * GPIOs themselves are made up of several attributes that are communicated as
31  * an nvlist_t. While most attributes are determined by the provider and are
32  * required to be prefixed as such, a few are standardized across everything.
33  *
34  * Note: At this time, the possible information only allows for fully enumerated
35  * lists of values. We should consider adding support for ranges ala mac.
36  */
37 #define	KGPIO_ATTR_NAME	"name"
38 #define	KGPIO_ATTR_META	"metadata"
39 #define	KGPIO_ATTR_PROT	"protection"
40 #define	KGPIO_ATTR_POS	"possible"
41 
42 typedef enum {
43 	KGPIO_PROT_RO,
44 	KGPIO_PROT_RW
45 } kgpio_prot_t;
46 
47 /*
48  * When setting attributes, these are valid reasons that an attribute may be
49  * invalid or not settable.
50  */
51 typedef enum {
52 	/*
53 	 * Actually, no problem.
54 	 */
55 	KGPIO_ATTR_ERR_OK,
56 	/*
57 	 * Indicates that an attempt was made to set a read-only attribute.
58 	 */
59 	KGPIO_ATTR_ERR_ATTR_RO,
60 	/*
61 	 * Indicates that the requested attribute was not known to the provider.
62 	 */
63 	KGPIO_ATTR_ERR_UNKNOWN_ATTR,
64 	/*
65 	 * Indicates that the attributes type is not correct.
66 	 */
67 	KGPIO_ATTR_ERR_BAD_TYPE,
68 	/*
69 	 * Indicates that the attribute's value was unknown to the provider.
70 	 */
71 	KGPIO_ATTR_ERR_UNKNOWN_VAL,
72 	/*
73 	 * Indicates that while the provider knows this value, it is not valid
74 	 * for this GPIO or for the GPIO in its current configuration (e.g.
75 	 * asking for a high push-pull output for an open-drain pin).
76 	 */
77 	KGPIO_ATTR_ERR_CANT_APPLY_VAL
78 } kgpio_attr_err_t;
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif /* _SYS_GPIO_KGPIO_ATTR_H */
85