summaryrefslogtreecommitdiffstats
path: root/src/include/gpxe/async.h
diff options
context:
space:
mode:
authorMichael Brown2006-05-31 16:34:17 +0200
committerMichael Brown2006-05-31 16:34:17 +0200
commit68125bc44173893fb3af08085b0b6b823b60d030 (patch)
treee93be1ff71e3b25a953947885a0c8379822694cf /src/include/gpxe/async.h
parentAdded drivers/ata directory (forgot to check this in previously). (diff)
downloadipxe-68125bc44173893fb3af08085b0b6b823b60d030.tar.gz
ipxe-68125bc44173893fb3af08085b0b6b823b60d030.tar.xz
ipxe-68125bc44173893fb3af08085b0b6b823b60d030.zip
Added generic asynchronous operations code.
Removed data_in_len and data_out_len from ata_command structure; the lengths are implied by the sector count and the presence of the data_in or data_out pointers. Changed AoE code to use subcommands by default, and made aoe_issue() nonblocking (with completion via async_wait()).
Diffstat (limited to 'src/include/gpxe/async.h')
-rw-r--r--src/include/gpxe/async.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/include/gpxe/async.h b/src/include/gpxe/async.h
new file mode 100644
index 00000000..8a681978
--- /dev/null
+++ b/src/include/gpxe/async.h
@@ -0,0 +1,62 @@
+#ifndef _GPXE_ASYNC_H
+#define _GPXE_ASYNC_H
+
+/** @file
+ *
+ * Asynchronous operations
+ *
+ */
+
+#include <errno.h>
+#include <assert.h>
+
+/** An asynchronous operation */
+struct async_operation {
+ /** Operation status
+ *
+ * This is an error code as defined in errno.h, plus an offset
+ * of EINPROGRESS. This means that a status value of 0
+ * corresponds to a return status code of -EINPROGRESS,
+ * i.e. that the default state of an asynchronous operation is
+ * "not yet completed".
+ */
+ int status;
+};
+
+/**
+ * Set asynchronous operation status
+ *
+ * @v aop Asynchronous operation
+ * @v rc Return status code
+ */
+static inline __attribute__ (( always_inline )) void
+async_set_status ( struct async_operation *aop, int rc ) {
+ aop->status = ( rc + EINPROGRESS );
+}
+
+/**
+ * Get asynchronous operation status
+ *
+ * @v aop Asynchronous operation
+ * @ret rc Return status code
+ */
+static inline __attribute__ (( always_inline )) int
+async_status ( struct async_operation *aop ) {
+ return ( aop->status - EINPROGRESS );
+}
+
+/**
+ * Flag asynchronous operation as complete
+ *
+ * @v aop Asynchronous operation
+ * @v rc Return status code
+ */
+static inline __attribute__ (( always_inline )) void
+async_done ( struct async_operation *aop, int rc ) {
+ assert ( rc != -EINPROGRESS );
+ async_set_status ( aop, rc );
+}
+
+extern int async_wait ( struct async_operation *aop );
+
+#endif /* _GPXE_ASYNC_H */