xref: /illumos-gate/usr/src/lib/libfru/libfruraw/fru_access.h (revision f012ee0c3db17469b492c2cf757226f3d7b1ebbc)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _FRU_ACCESS_H
28 #define	_FRU_ACCESS_H
29 
30 #include <sys/types.h>
31 #include <picl.h>
32 #include <door.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 
39 #define	SEG_NAME_LEN	2
40 
41 
42 typedef uint64_t  fru_hdl_t;
43 
44 typedef fru_hdl_t  container_hdl_t;
45 typedef fru_hdl_t  section_hdl_t;
46 typedef fru_hdl_t  segment_hdl_t;
47 typedef fru_hdl_t  packet_hdl_t;
48 
49 typedef struct
50 {
51 	section_hdl_t	handle;	/*  for use in operations on section  */
52 	uint32_t	offset;	/*  bytes from container beginning  */
53 	uint32_t	length;	/*  length of section in bytes  */
54 	uint32_t	protection; /* non-zero if section is write-protected */
55 	int32_t		version;	/*  version of section header, or -1 */
56 }
57 section_t;
58 
59 typedef struct
60 {
61 	segment_hdl_t	handle;	/*  for operations on segment  */
62 	char	name[SEG_NAME_LEN];	/*  from container section header  */
63 	uint32_t	descriptor;	/*  ditto  */
64 	uint32_t	offset;		/*  ditto  */
65 	uint32_t	length;		/*  ditto  */
66 }
67 segment_t;
68 
69 typedef uint64_t  tag_t;
70 
71 typedef struct
72 {
73 	packet_hdl_t	handle;	/*  for use in operations on packet  */
74 	tag_t		tag;
75 }
76 packet_t;
77 
78 
79 container_hdl_t fru_open_container(picl_nodehdl_t fru);
80 
81 int fru_close_container(container_hdl_t container);
82 int fru_get_num_sections(container_hdl_t container, door_cred_t *cred);
83 int fru_get_sections(container_hdl_t container, section_t *section,
84 				int max_sections, door_cred_t *cred);
85 int fru_get_num_segments(section_hdl_t section, door_cred_t *rarg);
86 int fru_get_segments(section_hdl_t section, segment_t *segment,
87 				int max_segments, door_cred_t *rarg);
88 int fru_add_segment(section_hdl_t section, segment_t *segment,
89 			section_hdl_t *newsection, door_cred_t *cred);
90 int fru_delete_segment(segment_hdl_t segment, section_hdl_t *newsection,
91 							door_cred_t *cred);
92 ssize_t fru_read_segment(segment_hdl_t segment, void *buffer, size_t nbytes,
93 							door_cred_t *cred);
94 int fru_write_segment(segment_hdl_t segment, const void *data, size_t nbytes,
95 				segment_hdl_t *newsegment, door_cred_t *cred);
96 int fru_get_num_packets(segment_hdl_t segment, door_cred_t *cred);
97 int fru_get_packets(segment_hdl_t segment, packet_t *packet,
98 			int max_packets, door_cred_t *cred);
99 ssize_t fru_get_payload(packet_hdl_t packet, void *buffer,
100 			size_t nbytes, door_cred_t *cred);
101 int fru_update_payload(packet_hdl_t packet, const void *data, size_t nbytes,
102 			packet_hdl_t *newpacket, door_cred_t *cred);
103 int fru_append_packet(segment_hdl_t segment, packet_t *packet,
104 	const void *payload, size_t nbytes, segment_hdl_t *newsegment,
105 						door_cred_t *cred);
106 int fru_delete_packet(packet_hdl_t packet, segment_hdl_t *newsegment,
107 						door_cred_t *cred);
108 int fru_is_data_available(picl_nodehdl_t fru);
109 
110 #ifdef	__cplusplus
111 }
112 #endif
113 
114 #endif /* _FRU_ACCESS_H */
115