|
| 1 | +// This file is a part of the IncludeOS unikernel - www.includeos.org |
| 2 | +// |
| 3 | +// Copyright 2015 Oslo and Akershus University College of Applied Sciences |
| 4 | +// and Alfred Bratterud |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | + |
| 18 | +#ifndef KERNEL_EVENTS_HPP |
| 19 | +#define KERNEL_EVENTS_HPP |
| 20 | + |
| 21 | +#include <delegate> |
| 22 | +#include <util/fixed_bitmap.hpp> |
| 23 | +#include <smp> |
| 24 | + |
| 25 | +#define IRQ_BASE 32 |
| 26 | + |
| 27 | +class alignas(SMP_ALIGN) Events { |
| 28 | +public: |
| 29 | + typedef void (*intr_func) (); |
| 30 | + using event_callback = delegate<void()>; |
| 31 | + |
| 32 | + static const size_t NUM_EVENTS = 128; |
| 33 | + |
| 34 | + uint8_t subscribe(event_callback); |
| 35 | + void subscribe(uint8_t evt, event_callback); |
| 36 | + void unsubscribe(uint8_t evt); |
| 37 | + |
| 38 | + // register event for deferred processing |
| 39 | + void trigger_event(uint8_t evt); |
| 40 | + |
| 41 | + /** |
| 42 | + * Get per-cpu instance |
| 43 | + */ |
| 44 | + static Events& get(); |
| 45 | + static Events& get(int cpu); |
| 46 | + |
| 47 | + /** process all pending events */ |
| 48 | + void process_events(); |
| 49 | + |
| 50 | + /** array of received events */ |
| 51 | + auto& get_received_array() const noexcept |
| 52 | + { return received_array; } |
| 53 | + |
| 54 | + /** array of handled events */ |
| 55 | + auto& get_handled_array() const noexcept |
| 56 | + { return handled_array; } |
| 57 | + |
| 58 | + void init_local(); |
| 59 | + Events() = default; |
| 60 | + |
| 61 | +private: |
| 62 | + Events(Events&) = delete; |
| 63 | + Events(Events&&) = delete; |
| 64 | + Events& operator=(Events&&) = delete; |
| 65 | + Events& operator=(Events&) = delete; |
| 66 | + |
| 67 | + event_callback callbacks[NUM_EVENTS]; |
| 68 | + std::array<uint64_t, NUM_EVENTS> received_array; |
| 69 | + std::array<uint64_t*,NUM_EVENTS> handled_array; |
| 70 | + |
| 71 | + Fixed_bitmap<NUM_EVENTS> event_subs; |
| 72 | + Fixed_bitmap<NUM_EVENTS> event_pend; |
| 73 | + Fixed_bitmap<NUM_EVENTS> event_todo; |
| 74 | +}; |
| 75 | + |
| 76 | +#endif //< KERNEL_EVENTS_HPP |
0 commit comments