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_DPIO_H 17 #define _SYS_GPIO_DPIO_H 18 19 /* 20 * Definitions that consumers of DPIOs should likely know about. 21 */ 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* 28 * This is the general size of names in the dpio structures. Actual name lengths 29 * and limits are potentially less. 30 */ 31 #define DPIO_NAMELEN 64 32 33 /* 34 * Basic IOCTL information 35 */ 36 #define DPIO_IOC (('d' << 24) | ('p' << 16) | ('i' << 8)) 37 38 /* 39 * This is the set of values that are expected on a write(2) to a DPIO to set 40 * the output state. Each write(2) must be a uint32_t (4 bytes) in size. 41 */ 42 typedef enum { 43 DPIO_OUTPUT_LOW = 0, 44 DPIO_OUTPUT_HIGH = 1, 45 DPIO_OUTPUT_DISABLE = UINT32_MAX 46 } dpio_output_t; 47 48 /* 49 * This is the set of values that are expected on a read(2) of a DPIO to get the 50 * input state. Each read(2) must be a uint32_t (4 bytes) in size. 51 */ 52 typedef enum { 53 DPIO_INPUT_LOW = 0, 54 DPIO_INPUT_HIGH = 1 55 } dpio_input_t; 56 57 /* 58 * This indicates features that the DPIO is set up for and supports. 59 */ 60 typedef enum { 61 DPIO_C_READ = 1 << 0, 62 DPIO_C_WRITE = 1 << 1, 63 DPIO_C_POLL = 1 << 2 64 } dpio_caps_t; 65 66 typedef enum { 67 DPIO_F_KERNEL = 1 << 0, 68 } dpio_flags_t; 69 70 /* 71 * This is the basic information structure for a DPIO. It reports information 72 * about what is supported and usable. This is accessible via the dpinfo 73 * interface or via the dpio itself. If this is called directly on a dpio 74 * itself, then the dpi_dpio field will be the DPIO's name. 75 */ 76 #define DPIO_IOC_INFO (DPIO_IOC | 1) 77 typedef struct { 78 char dpi_dpio[DPIO_NAMELEN]; 79 char dpi_ctrl[DPIO_NAMELEN]; 80 uint32_t dpi_gpio; 81 dpio_caps_t dpi_caps; 82 dpio_flags_t dpi_flags; 83 uint32_t dpi_pad; 84 } dpio_info_t; 85 86 /* 87 * This is used to get information about the current timing information. If the 88 * system supports interrupts on changes and it has been enabled, then this will 89 * be used to indicate the last time we received an update. 90 */ 91 #define DPIO_IOC_TIMING (DPIO_IOC | 2) 92 typedef struct { 93 hrtime_t dpt_last_input_intr; 94 hrtime_t dpt_last_write; 95 } dpio_timing_t; 96 97 /* 98 * This is used to get access to the current output state that has been set on 99 * the DPIO. This is only available via the dpio itself, it is not available via 100 * dpinfo as it is information specific to current consumers. 101 */ 102 #define DPIO_IOC_CUROUT (DPIO_IOC | 3) 103 typedef struct { 104 dpio_output_t dps_curout; 105 uint32_t dps_pad; 106 } dpio_curout_t; 107 108 #ifdef __cplusplus 109 } 110 #endif 111 112 #endif /* _SYS_GPIO_DPIO_H */ 113