paul@181 | 1 | /* |
paul@181 | 2 | * Interrupt request handling. |
paul@181 | 3 | * |
paul@181 | 4 | * Copyright (C) 2018, 2019, 2021 Paul Boddie <paul@boddie.org.uk> |
paul@181 | 5 | * |
paul@181 | 6 | * This program is free software; you can redistribute it and/or |
paul@181 | 7 | * modify it under the terms of the GNU General Public License as |
paul@181 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@181 | 9 | * the License, or (at your option) any later version. |
paul@181 | 10 | * |
paul@181 | 11 | * This program is distributed in the hope that it will be useful, |
paul@181 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@181 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@181 | 14 | * GNU General Public License for more details. |
paul@181 | 15 | * |
paul@181 | 16 | * You should have received a copy of the GNU General Public License |
paul@181 | 17 | * along with this program; if not, write to the Free Software |
paul@181 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@181 | 19 | * Boston, MA 02110-1301, USA |
paul@181 | 20 | */ |
paul@181 | 21 | |
paul@181 | 22 | #include <l4/re/env.h> |
paul@181 | 23 | #include <l4/sys/factory.h> |
paul@181 | 24 | #include <l4/sys/irq.h> |
paul@181 | 25 | #include <l4/sys/rcv_endpoint.h> |
paul@181 | 26 | |
paul@181 | 27 | #include "cap_alloc.h" |
paul@181 | 28 | #include "irq.h" |
paul@181 | 29 | |
paul@181 | 30 | |
paul@181 | 31 | |
paul@181 | 32 | /* IRQ operations. */ |
paul@181 | 33 | |
paul@181 | 34 | /* Create an interrupt request object. */ |
paul@181 | 35 | |
paul@181 | 36 | long ipc_create_irq(l4_cap_idx_t *irq) |
paul@181 | 37 | { |
paul@181 | 38 | long err; |
paul@181 | 39 | |
paul@181 | 40 | *irq = ipc_cap_alloc(); |
paul@181 | 41 | |
paul@181 | 42 | if (l4_is_invalid_cap(*irq)) |
paul@181 | 43 | return -L4_ENOENT; |
paul@181 | 44 | |
paul@181 | 45 | err = l4_error(l4_factory_create_irq(l4re_env()->factory, *irq)); |
paul@181 | 46 | |
paul@181 | 47 | if (err) |
paul@181 | 48 | { |
paul@181 | 49 | ipc_cap_free_um(*irq); |
paul@181 | 50 | return err; |
paul@181 | 51 | } |
paul@181 | 52 | |
paul@181 | 53 | return L4_EOK; |
paul@181 | 54 | } |
paul@181 | 55 | |
paul@181 | 56 | /* Initialise an interrupt request object for subsequent notifications. */ |
paul@181 | 57 | |
paul@181 | 58 | l4_msgtag_t ipc_init_irq(l4_cap_idx_t irq) |
paul@181 | 59 | { |
paul@181 | 60 | return l4_irq_unmask(irq); |
paul@181 | 61 | } |
paul@181 | 62 | |
paul@181 | 63 | /* Prepare a thread to receive IRQ object notifications. */ |
paul@181 | 64 | |
paul@181 | 65 | long ipc_bind_irq(l4_cap_idx_t irq, l4_umword_t id, l4_cap_idx_t thread) |
paul@181 | 66 | { |
paul@181 | 67 | long err = l4_error(l4_rcv_ep_bind_thread(irq, thread, id)); |
paul@181 | 68 | |
paul@181 | 69 | if (err) |
paul@181 | 70 | return err; |
paul@181 | 71 | |
paul@181 | 72 | return L4_EOK; |
paul@181 | 73 | } |