1.1 --- a/libfsserver/lib/pipes/pipe_paging.cc Sat May 15 23:38:39 2021 +0200
1.2 +++ b/libfsserver/lib/pipes/pipe_paging.cc Tue May 18 00:55:20 2021 +0200
1.3 @@ -19,6 +19,10 @@
1.4 * Boston, MA 02110-1301, USA
1.5 */
1.6
1.7 +#include <l4/sys/irq.h>
1.8 +
1.9 +#include <ipc/cap_alloc.h>
1.10 +#include <ipc/irq.h>
1.11 #include <mem/memory_incremental.h>
1.12 #include <mem/memory_preallocated.h>
1.13
1.14 @@ -40,6 +44,48 @@
1.15
1.16 for (unsigned int i = 0; i < 2; i++)
1.17 _regions[i] = NULL;
1.18 +
1.19 + /* Initialise IRQ objects for notifications. */
1.20 +
1.21 + for (unsigned int i = 0; i < 2; i++)
1.22 + _irqs[i] = L4_INVALID_CAP;
1.23 +}
1.24 +
1.25 +/* Create an IRQ to subscribe to an endpoint's notifications. */
1.26 +
1.27 +l4_cap_idx_t PipePaging::subscribe(bool writing)
1.28 +{
1.29 + int i = writing ? 1 : 0;
1.30 +
1.31 + if (l4_is_invalid_cap(_irqs[i]))
1.32 + ipc_create_irq(&_irqs[i]);
1.33 +
1.34 + return _irqs[i];
1.35 +}
1.36 +
1.37 +/* Release any IRQ used for an endpoint's notifications. */
1.38 +
1.39 +void PipePaging::unsubscribe(bool writing)
1.40 +{
1.41 + int i = writing ? 1 : 0;
1.42 +
1.43 + if (l4_is_valid_cap(_irqs[i]))
1.44 + {
1.45 + ipc_cap_free_um(_irqs[i]);
1.46 + _irqs[i] = L4_INVALID_CAP;
1.47 + }
1.48 +}
1.49 +
1.50 +/* Notify the other endpoint. */
1.51 +
1.52 +void PipePaging::notify(bool writing)
1.53 +{
1.54 + /* Let the writer notify the reader, and the other way round. */
1.55 +
1.56 + int i = writing ? 0 : 1;
1.57 +
1.58 + if (l4_is_valid_cap(_irqs[i]))
1.59 + l4_irq_trigger(_irqs[i]);
1.60 }
1.61
1.62 /* Return whether one or more endpoints have detached. */
1.63 @@ -77,6 +123,17 @@
1.64 }
1.65 }
1.66
1.67 + /* Release IRQs. */
1.68 +
1.69 + for (unsigned int i = 0; i < 2; i++)
1.70 + {
1.71 + if (l4_is_valid_cap(_irqs[i]))
1.72 + {
1.73 + ipc_cap_free_um(_irqs[i]);
1.74 + _irqs[i] = L4_INVALID_CAP;
1.75 + }
1.76 + }
1.77 +
1.78 /* Delete the page collection and related objects. */
1.79
1.80 delete _pages;
1.81 @@ -108,6 +165,13 @@
1.82 mapper->set_data_size(0);
1.83
1.84 _regions[_writing] = mapper;
1.85 +
1.86 + /* Let the writer notify the reader. */
1.87 +
1.88 + notify(true);
1.89 +
1.90 + /* Return the next region's mapper. */
1.91 +
1.92 return mapper;
1.93 }
1.94
1.95 @@ -144,6 +208,10 @@
1.96
1.97 _reading = 1 - _reading;
1.98
1.99 + /* Let the reader notify the writer. */
1.100 +
1.101 + notify(false);
1.102 +
1.103 /* Return the next region's mapper. */
1.104
1.105 return _regions[_reading];