From c504c1d6937a07b038ad21646eaec51f34684736 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 16 Oct 2020 14:59:36 +0100 Subject: [interface] Allow for the definition of an unused interface operation Allow an interface operation to be declared as unused. This will perform full type-checking and compilation of the implementing method, without including any code in the resulting object (other than a NULL entry in the interface operations table). The intention is to provide a relatively clean way for interface operation methods to be omitted in builds for which the operation is not required (such as an operation to describe an object using an EFI device path, which would not be required in a non-EFI build). Signed-off-by: Michael Brown --- src/include/ipxe/interface.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/include/ipxe/interface.h') diff --git a/src/include/ipxe/interface.h b/src/include/ipxe/interface.h index b65002c80..9281aeef5 100644 --- a/src/include/ipxe/interface.h +++ b/src/include/ipxe/interface.h @@ -36,6 +36,21 @@ struct interface_operation { ? op_func : op_func ), \ } +/** + * Define an unused object interface operation + * + * @v op_type Operation type + * @v object_type Implementing method's expected object type + * @v op_func Implementing method + * @ret op Object interface operation + */ +#define UNUSED_INTF_OP( op_type, object_type, op_func ) { \ + .type = NULL, \ + .func = ( ( ( ( typeof ( op_func ) * ) NULL ) == \ + ( ( op_type ## _TYPE ( object_type ) * ) NULL ) ) \ + ? NULL : NULL ), \ + } + /** An object interface descriptor */ struct interface_descriptor { /** Offset of interface within containing object */ -- cgit v1.2.3-55-g7522 From 09fe2bbd343a46010e89d848e5887bfb5fc3f6f6 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 7 Dec 2020 13:49:47 +0000 Subject: [interface] Provide intf_insert() to insert a filter interface Generalise the filter interface insertion logic from block_translate() and expose as intf_insert(), allowing a filter interface to be inserted on any existing interface. Signed-off-by: Michael Brown --- src/core/blocktrans.c | 4 +--- src/core/interface.c | 17 +++++++++++++++++ src/include/ipxe/interface.h | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) (limited to 'src/include/ipxe/interface.h') diff --git a/src/core/blocktrans.c b/src/core/blocktrans.c index 3f32f9cf8..f9dcb95d2 100644 --- a/src/core/blocktrans.c +++ b/src/core/blocktrans.c @@ -242,9 +242,7 @@ int block_translate ( struct interface *block, userptr_t buffer, size_t size ) { } /* Attach to interfaces, mortalise self, and return */ - assert ( block->dest != &null_intf ); - intf_plug_plug ( &blktrans->xfer, block->dest ); - intf_plug_plug ( &blktrans->block, block ); + intf_insert ( block, &blktrans->block, &blktrans->xfer ); ref_put ( &blktrans->refcnt ); DBGC2 ( blktrans, "BLKTRANS %p created", blktrans ); diff --git a/src/core/interface.c b/src/core/interface.c index 05e7e4777..34a4180a5 100644 --- a/src/core/interface.c +++ b/src/core/interface.c @@ -390,6 +390,23 @@ void intfs_restart ( int rc, ... ) { va_end ( intfs ); } +/** + * Insert a filter interface + * + * @v intf Object interface + * @v upper Upper end of filter + * @v lower Lower end of filter + */ +void intf_insert ( struct interface *intf, struct interface *upper, + struct interface *lower ) { + struct interface *dest = intf->dest; + + intf_get ( dest ); + intf_plug_plug ( intf, upper ); + intf_plug_plug ( lower, dest ); + intf_put ( dest ); +} + /** * Poke an object interface * diff --git a/src/include/ipxe/interface.h b/src/include/ipxe/interface.h index 9281aeef5..19f58a4b4 100644 --- a/src/include/ipxe/interface.h +++ b/src/include/ipxe/interface.h @@ -169,6 +169,8 @@ extern void intfs_shutdown ( int rc, ... ) __attribute__ (( sentinel )); extern void intf_restart ( struct interface *intf, int rc ); extern void intfs_vrestart ( va_list intfs, int rc ); extern void intfs_restart ( int rc, ... ) __attribute__ (( sentinel )); +extern void intf_insert ( struct interface *intf, struct interface *upper, + struct interface *lower ); extern void intf_poke ( struct interface *intf, void ( type ) ( struct interface *intf ) ); -- cgit v1.2.3-55-g7522