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 2025 Oxide Computer Company 14 */ 15 16 #ifndef _EEDEV_H 17 #define _EEDEV_H 18 19 /* 20 * A small set of utilities to make reading and writing EEPROM class devices 21 * simpler. Right now this mostly just facilitates reading and writing. 22 */ 23 24 #include <sys/types.h> 25 #include <sys/uio.h> 26 #include <sys/cred.h> 27 #include <sys/devops.h> 28 #include <sys/stdbool.h> 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 #define EEDEV_REG_VERS0 0 35 #define EEDEV_REG_VERS EEDEV_REG_VERS0 36 37 /* 38 * The maximum number of characters in a name for a device. Only alphanumeric 39 * characters and '_' and '-' are allowed in the name. 40 */ 41 #define EEDEV_NAME_MAX 32 42 43 typedef struct { 44 int (*eo_read)(void *, uio_t *, uint32_t, uint32_t, uint32_t); 45 int (*eo_write)(void *, uio_t *, uint32_t, uint32_t, uint32_t); 46 } eedev_ops_t; 47 48 typedef struct { 49 uint32_t ereg_vers; 50 /* 51 * Size of the device in bytes. 52 */ 53 uint32_t ereg_size; 54 /* 55 * This is the size and alignment of a given page in a device. If this 56 * is left as zero, then the device can address all of the data without 57 * taking action. 58 */ 59 uint32_t ereg_seg; 60 /* 61 * This is the access granularity or the number of bytes per address in 62 * the device. For example, a 512-byte device with an access granularity 63 * of 2, would have 256 2-byte addresses available. 64 */ 65 uint32_t ereg_read_gran; 66 uint32_t ereg_write_gran; 67 /* 68 * This is the maximum number of bytes that can be in a read or write 69 * request in one go. A value of zero means the device doesn't care. 70 */ 71 uint32_t ereg_max_read; 72 uint32_t ereg_max_write; 73 /* 74 * Is the device read-only. If this is false, then it is an error to not 75 * include a write operation. 76 */ 77 bool ereg_ro; 78 uint8_t ereg_rsvd[3]; 79 /* 80 * Identifying information. The dip is what device this belongs to. The 81 * name is the name that should be used. If left NULL a default name of 82 * "eeprom" will be used. If the driver is going to create more than a 83 * single device per dev_info_t, it should fill this in. The minor 84 * should be a minor allocated by the driver for use here. 85 */ 86 dev_info_t *ereg_dip; 87 void *ereg_driver; 88 const char *ereg_name; 89 const eedev_ops_t *ereg_ops; 90 } eedev_reg_t; 91 92 typedef struct eedev_hdl eedev_hdl_t; 93 94 /* 95 * Functions to create and finish an eedev handle. 96 */ 97 extern int eedev_create(const eedev_reg_t *, eedev_hdl_t **); 98 extern void eedev_fini(eedev_hdl_t *); 99 100 #ifdef __cplusplus 101 } 102 #endif 103 104 #endif /* _EEDEV_H */ 105