iPXE
interface.h
Go to the documentation of this file.
1#ifndef _IPXE_INTERFACE_H
2#define _IPXE_INTERFACE_H
3
4/** @file
5 *
6 * Object interfaces
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stddef.h>
14#include <stdarg.h>
15#include <ipxe/refcnt.h>
16
17/** An object interface operation */
19 /** Operation type */
20 void *type;
21 /** Implementing method */
22 void *func;
23};
24
25/**
26 * Define an object interface operation
27 *
28 * @v op_type Operation type
29 * @v object_type Implementing method's expected object type
30 * @v op_func Implementing method
31 * @ret op Object interface operation
32 */
33#define INTF_OP( op_type, object_type, op_func ) { \
34 .type = op_type, \
35 .func = ( ( ( ( typeof ( op_func ) * ) NULL ) == \
36 ( ( op_type ## _TYPE ( object_type ) * ) NULL ) ) \
37 ? op_func : op_func ), \
38 }
39
40/**
41 * Define an unused object interface operation
42 *
43 * @v op_type Operation type
44 * @v object_type Implementing method's expected object type
45 * @v op_func Implementing method
46 * @ret op Object interface operation
47 */
48#define UNUSED_INTF_OP( op_type, object_type, op_func ) { \
49 .type = NULL, \
50 .func = ( ( ( ( typeof ( op_func ) * ) NULL ) == \
51 ( ( op_type ## _TYPE ( object_type ) * ) NULL ) ) \
52 ? NULL : NULL ), \
53 }
54
55/** An object interface descriptor */
57 /** Offset of interface within containing object */
58 size_t offset;
59 /** Number of interface operations */
60 unsigned int num_op;
61 /** Object interface operations */
63 /** Offset to pass-through interface, if present */
65};
66
67#define intf_offset( object_type, intf ) \
68 ( ( ( ( typeof ( ( ( object_type * ) NULL )->intf ) * ) NULL ) \
69 == ( ( struct interface * ) NULL ) ) \
70 ? offsetof ( object_type, intf ) \
71 : offsetof ( object_type, intf ) )
72
73/**
74 * Define an object interface descriptor
75 *
76 * @v object_type Containing object data type
77 * @v intf Interface name (i.e. field within object data type)
78 * @v operations Object interface operations array
79 * @ret desc Object interface descriptor
80 */
81#define INTF_DESC( object_type, intf, operations ) { \
82 .offset = intf_offset ( object_type, intf ), \
83 .op = operations, \
84 .num_op = ( sizeof ( operations ) / \
85 sizeof ( operations[0] ) ), \
86 .passthru_offset = 0, \
87 }
88
89/**
90 * Define an object interface descriptor with pass-through interface
91 *
92 * @v object_type Containing object data type
93 * @v intf Interface name (i.e. field within object data type)
94 * @v operations Object interface operations array
95 * @v passthru Pass-through interface name
96 * @ret desc Object interface descriptor
97 */
98#define INTF_DESC_PASSTHRU( object_type, intf, operations, passthru ) { \
99 .offset = offsetof ( object_type, intf ), \
100 .op = operations, \
101 .num_op = ( sizeof ( operations ) / \
102 sizeof ( operations[0] ) ), \
103 .passthru_offset = ( intf_offset ( object_type, passthru ) - \
104 intf_offset ( object_type, intf ) ), \
105 }
106
107/**
108 * Define an object interface descriptor for a pure-interface object
109 *
110 * @v operations Object interface operations array
111 * @ret desc Object interface descriptor
112 *
113 * A pure-interface object is an object that consists solely of a
114 * single interface.
115 */
116#define INTF_DESC_PURE( operations ) { \
117 .offset = 0, \
118 .op = operations, \
119 .num_op = ( sizeof ( operations ) / \
120 sizeof ( operations[0] ) ), \
121 .passthru_offset = 0, \
122 }
123
124/** An object interface */
125struct interface {
126 /** Destination object interface
127 *
128 * When the containing object invokes an operation on this
129 * interface, it will be executed by the destination object.
130 *
131 * This pointer may never be NULL. When the interface is
132 * unplugged, it should point to the null interface.
133 */
135 /** Reference counter
136 *
137 * If this interface is not part of a reference-counted object
138 * then this field is NULL.
139 */
140 struct refcnt *refcnt;
141 /** Interface descriptor
142 *
143 * If this is a temporary outbound-only interface created by
144 * intf_temp_init() then this field is NULL.
145 */
147 /** Original interface properties */
148 union {
149 /** Original interface descriptor
150 *
151 * Used by intf_reinit().
152 */
154 /** Original interface
155 *
156 * Used for temporary outbound-only interfaces created
157 * by intf_temp_init().
158 */
161};
162
163extern void intf_plug ( struct interface *intf, struct interface *dest );
164extern void intf_plug_plug ( struct interface *a, struct interface *b );
165extern void intf_unplug ( struct interface *intf );
166extern void intf_nullify ( struct interface *intf );
167extern struct interface * intf_get ( struct interface *intf );
168extern void intf_put ( struct interface *intf );
169extern void * __attribute__ (( pure )) intf_object ( struct interface *intf );
171 void *type,
172 struct interface **dest );
173extern void * intf_get_dest_op_untyped ( struct interface *intf, void *type,
174 struct interface **dest );
175
176extern void intf_close ( struct interface *intf, int rc );
177#define intf_close_TYPE( object_type ) \
178 typeof ( void ( object_type, int rc ) )
179
180extern void intf_shutdown ( struct interface *intf, int rc );
181extern void intfs_vshutdown ( va_list intfs, int rc );
182extern void intfs_shutdown ( int rc, ... ) __attribute__ (( sentinel ));
183extern void intf_restart ( struct interface *intf, int rc );
184extern void intfs_vrestart ( va_list intfs, int rc );
185extern void intfs_restart ( int rc, ... ) __attribute__ (( sentinel ));
186extern void intf_insert ( struct interface *intf, struct interface *upper,
187 struct interface *lower );
188
189extern void intf_poke ( struct interface *intf,
190 void ( type ) ( struct interface *intf ) );
191#define intf_poke_TYPE( object_type ) \
192 typeof ( void ( object_type ) )
193
195extern struct interface null_intf;
196
197/**
198 * Initialise an object interface
199 *
200 * @v intf Object interface
201 * @v desc Object interface descriptor
202 * @v refcnt Containing object reference counter, or NULL
203 */
204static inline void intf_init ( struct interface *intf,
206 struct refcnt *refcnt ) {
207 intf->dest = &null_intf;
208 intf->refcnt = refcnt;
209 intf->desc = desc;
211}
212
213/**
214 * Initialise a static object interface
215 *
216 * @v descriptor Object interface descriptor
217 */
218#define INTF_INIT( descriptor ) { \
219 .dest = &null_intf, \
220 .refcnt = NULL, \
221 .desc = &(descriptor), \
222 .original = { \
223 .desc = &(descriptor), \
224 }, \
225 }
226
227/**
228 * Initialise a temporary outbound-only object interface
229 *
230 * @v intf Temporary outbound-only object interface
231 * @v original Original object interface
232 */
233static inline void intf_temp_init ( struct interface *intf,
234 struct interface *original ) {
235 intf->dest = &null_intf;
236 intf->desc = NULL;
238}
239
240/**
241 * Get original interface
242 *
243 * @v intf Object interface (possibly a temporary interface)
244 * @ret intf Original object interface
245 */
246static inline struct interface * intf_origin ( struct interface *intf ) {
247 return ( intf->desc ? intf : intf->original.intf );
248}
249
250/**
251 * Get object interface destination and operation method (without pass-through)
252 *
253 * @v intf Object interface
254 * @v type Operation type
255 * @ret dest Destination interface
256 * @ret func Implementing method, or NULL
257 */
258#define intf_get_dest_op_no_passthru( intf, type, dest ) \
259 ( ( type ## _TYPE ( void * ) * ) \
260 intf_get_dest_op_no_passthru_untyped ( intf, type, dest ) )
261
262/**
263 * Get object interface destination and operation method
264 *
265 * @v intf Object interface
266 * @v type Operation type
267 * @ret dest Destination interface
268 * @ret func Implementing method, or NULL
269 */
270#define intf_get_dest_op( intf, type, dest ) \
271 ( ( type ## _TYPE ( void * ) * ) \
272 intf_get_dest_op_untyped ( intf, type, dest ) )
273
274/**
275 * Find debugging colourisation for an object interface
276 *
277 * @v intf Object interface
278 * @ret col Debugging colourisation
279 *
280 * Use as the first argument to DBGC() or equivalent macro.
281 */
282#define INTF_COL( intf ) intf_object ( intf_origin ( intf ) )
283
284/** printf() format string for INTF_DBG() */
285#define INTF_FMT "%p+%zx"
286
287/**
288 * printf() arguments for representing an object interface
289 *
290 * @v intf Object interface
291 * @ret args printf() argument list corresponding to INTF_FMT
292 */
293#define INTF_DBG( intf ) \
294 intf_object ( intf_origin ( intf ) ), \
295 intf_origin ( intf )->desc->offset
296
297/** printf() format string for INTF_INTF_DBG() */
298#define INTF_INTF_FMT INTF_FMT "->" INTF_FMT
299
300/**
301 * printf() arguments for representing an object interface pair
302 *
303 * @v intf Object interface
304 * @v dest Destination object interface
305 * @ret args printf() argument list corresponding to INTF_INTF_FMT
306 */
307#define INTF_INTF_DBG( intf, dest ) INTF_DBG ( intf ), INTF_DBG ( dest )
308
309/**
310 * Reinitialise an object interface
311 *
312 * @v intf Object interface
313 */
314static inline void intf_reinit ( struct interface *intf ) {
315
316 /* Restore original interface descriptor */
318}
319
320#endif /* _IPXE_INTERFACE_H */
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
signed long ssize_t
Definition stdint.h:7
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
Definition string.h:151
uint32_t type
Operating system type.
Definition ena.h:1
struct ena_llq_option desc
Descriptor counts.
Definition ena.h:9
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define __attribute__(x)
Definition compiler.h:10
void intfs_vrestart(va_list intfs, int rc)
Shut down and restart multiple object interfaces.
Definition interface.c:367
void intfs_restart(int rc,...)
Shut down and restart multiple object interfaces.
Definition interface.c:387
struct interface null_intf
The null interface.
Definition interface.c:66
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition interface.c:160
struct interface_descriptor null_intf_desc
Null interface descriptor.
Definition interface.c:62
void intf_poke(struct interface *intf, void(type)(struct interface *intf))
Poke an object interface.
Definition interface.c:421
void intf_insert(struct interface *intf, struct interface *upper, struct interface *lower)
Insert a filter interface.
Definition interface.c:402
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition interface.c:344
void * intf_get_dest_op_untyped(struct interface *intf, void *type, struct interface **dest)
Get object interface destination and operation method.
Definition interface.c:213
void * intf_get_dest_op_no_passthru_untyped(struct interface *intf, void *type, struct interface **dest)
Get object interface destination and operation method (without pass-through)
Definition interface.c:188
static void intf_temp_init(struct interface *intf, struct interface *original)
Initialise a temporary outbound-only object interface.
Definition interface.h:233
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition interface.c:250
static void intf_reinit(struct interface *intf)
Reinitialise an object interface.
Definition interface.h:314
struct interface * intf_get(struct interface *intf)
Increment reference count on an object interface.
Definition interface.c:140
void intf_plug(struct interface *intf, struct interface *dest)
Plug an object interface into a new destination object interface.
Definition interface.c:84
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition interface.h:204
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition interface.c:108
void intfs_shutdown(int rc,...) __attribute__((sentinel))
Shut down multiple object interfaces.
Definition interface.c:327
static struct interface * intf_origin(struct interface *intf)
Get original interface.
Definition interface.h:246
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition interface.c:150
void intf_unplug(struct interface *intf)
Unplug an object interface.
Definition interface.c:118
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition interface.c:279
void intfs_vshutdown(va_list intfs, int rc)
Shut down multiple object interfaces.
Definition interface.c:306
void intf_nullify(struct interface *intf)
Ignore all further operations on an object interface.
Definition interface.c:130
Reference counting.
__builtin_va_list va_list
Definition stdarg.h:7
An object interface descriptor.
Definition interface.h:56
size_t offset
Offset of interface within containing object.
Definition interface.h:58
ssize_t passthru_offset
Offset to pass-through interface, if present.
Definition interface.h:64
struct interface_operation * op
Object interface operations.
Definition interface.h:62
unsigned int num_op
Number of interface operations.
Definition interface.h:60
An object interface operation.
Definition interface.h:18
void * func
Implementing method.
Definition interface.h:22
void * type
Operation type.
Definition interface.h:20
An object interface.
Definition interface.h:125
struct interface * dest
Destination object interface.
Definition interface.h:134
struct interface_descriptor * desc
Interface descriptor.
Definition interface.h:146
struct interface * intf
Original interface.
Definition interface.h:159
struct refcnt * refcnt
Reference counter.
Definition interface.h:140
union interface::@153016120005256257222347015034114015314175051044 original
Original interface properties.
A reference counter.
Definition refcnt.h:27