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