Adam Barth | 57eacf5 | 2020-11-04 00:38:09 +0000 | [diff] [blame^] | 1 | // Copyright 2017 The Fuchsia Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef LIB_ASYNC_IRQ_H_ |
| 6 | #define LIB_ASYNC_IRQ_H_ |
| 7 | |
| 8 | #include <lib/async/dispatcher.h> |
| 9 | |
| 10 | __BEGIN_CDECLS |
| 11 | |
| 12 | // Handles interrupt. |
| 13 | // |
| 14 | // The |status| is |ZX_OK| if the IRQ was signalled. |
| 15 | // The |status| is |ZX_ERR_CANCELED| if the dispatcher was shut down before |
| 16 | // the task's handler ran or the task was canceled. |
| 17 | typedef void(async_irq_handler_t)(async_dispatcher_t* dispatcher, async_irq_t* irq, |
| 18 | zx_status_t status, const zx_packet_interrupt_t* signal); |
| 19 | |
| 20 | // Similar to async_wait, but holds state for an interrupt. |
| 21 | struct async_irq { |
| 22 | // Private state owned by the dispatcher, initialize to zero with |ASYNC_STATE_INIT|. |
| 23 | async_state_t state; |
| 24 | |
| 25 | // The wait's handler function. |
| 26 | async_irq_handler_t* handler; |
| 27 | |
| 28 | // The object to wait for signals on. |
| 29 | zx_handle_t object; |
| 30 | }; |
| 31 | |
| 32 | // Begins asynchronously waiting on an IRQ specified in |irq|. |
| 33 | // Invokes the handler when the wait completes. |
| 34 | // The wait's handler will be invoked exactly once unless the wait is canceled. |
| 35 | // When the dispatcher is shutting down (being destroyed), the handlers of |
| 36 | // all remaining waits will be invoked with a status of |ZX_ERR_CANCELED|. |
| 37 | // |
| 38 | // Returns |ZX_OK| if the wait was successfully begun. |
| 39 | // Returns |ZX_ERR_BAD_STATE| if the dispatcher is shutting down. |
| 40 | // Returns |ZX_ERR_NOT_SUPPORTED| if not supported by the dispatcher. |
| 41 | // |
| 42 | // This operation is thread-safe. |
| 43 | zx_status_t async_bind_irq(async_dispatcher_t* dispatcher, async_irq_t* irq); |
| 44 | |
| 45 | // Unbinds the IRQ associated with |irq|. |
| 46 | // |
| 47 | // If successful, the IRQ will be unbound from the async loop. |
| 48 | // |
| 49 | // Returns |ZX_OK| if the IRQ has been successfully unbound. |
| 50 | // Returns |ZX_ERR_NOT_SUPPORTED| if not supported by the dispatcher. |
| 51 | // |
| 52 | // This operation is thread-safe. |
| 53 | zx_status_t async_unbind_irq(async_dispatcher_t* dispatcher, async_irq_t* irq); |
| 54 | |
| 55 | __END_CDECLS |
| 56 | |
| 57 | #endif // LIB_ASYNC_IRQ_H_ |