Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 1 | /* |
Gerwin Klein | 600fe15 | 2021-02-10 19:19:17 +1100 | [diff] [blame] | 2 | * Copyright 2017, Data61, CSIRO (ABN 41 687 119 230) |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 3 | * |
Gerwin Klein | 600fe15 | 2021-02-10 19:19:17 +1100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-2-Clause |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 5 | */ |
| 6 | #include <autoconf.h> |
Yu Hou | e23dc54 | 2019-05-20 15:29:15 +1000 | [diff] [blame] | 7 | #include <sel4platsupport/gen_config.h> |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 8 | #include <sel4platsupport/device.h> |
Anna Lyons | 882395e | 2017-07-20 11:07:46 +1000 | [diff] [blame] | 9 | #include <sel4platsupport/irq.h> |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 10 | #include <sel4platsupport/platsupport.h> |
Matthew Fernandez | 9270216 | 2016-06-10 15:35:43 +1000 | [diff] [blame] | 11 | #include <stddef.h> |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 12 | #include <vka/capops.h> |
| 13 | #include <utils/util.h> |
| 14 | |
Yu Hou | e9a9ff4 | 2019-07-18 17:26:01 +1000 | [diff] [blame] | 15 | seL4_Error sel4platsupport_copy_irq_cap(vka_t *vka, simple_t *simple, ps_irq_t *irq, cspacepath_t *dest) |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 16 | { |
Anna Lyons | 882395e | 2017-07-20 11:07:46 +1000 | [diff] [blame] | 17 | seL4_CPtr cap; |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 18 | |
| 19 | /* allocate a cslot for the irq cap */ |
Anna Lyons | 882395e | 2017-07-20 11:07:46 +1000 | [diff] [blame] | 20 | int error = vka_cspace_alloc(vka, &cap); |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 21 | if (error != 0) { |
Adrian Danis | a0b6bbf | 2017-01-11 17:15:49 +1100 | [diff] [blame] | 22 | ZF_LOGE("Failed to allocate cslot for irq"); |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 23 | return error; |
| 24 | } |
| 25 | |
Anna Lyons | 882395e | 2017-07-20 11:07:46 +1000 | [diff] [blame] | 26 | vka_cspace_make_path(vka, cap, dest); |
| 27 | assert(irq->type != PS_NONE); |
| 28 | if (irq->type == PS_INTERRUPT) { |
| 29 | error = simple_get_IRQ_handler(simple, irq->irq.number, *dest); |
| 30 | } else { |
| 31 | error = sel4platsupport_arch_copy_irq_cap(&simple->arch_simple, irq, dest); |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 32 | } |
| 33 | |
Yu Hou | e9a9ff4 | 2019-07-18 17:26:01 +1000 | [diff] [blame] | 34 | if (error != seL4_NoError) { |
Anna Lyons | 882395e | 2017-07-20 11:07:46 +1000 | [diff] [blame] | 35 | ZF_LOGE("Failed to get cap for irq"); |
| 36 | vka_cspace_free(vka, cap); |
| 37 | } |
| 38 | return error; |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 39 | } |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 40 | |
Yu Hou | e9a9ff4 | 2019-07-18 17:26:01 +1000 | [diff] [blame] | 41 | seL4_Error sel4platsupport_alloc_frame_at(vka_t *vka, uintptr_t paddr, size_t size_bits, vka_object_t *frame) |
Anna Lyons | 76fcd2c | 2016-10-05 12:21:33 +1100 | [diff] [blame] | 42 | { |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 43 | /* find the physical frame */ |
Anna Lyons | 76fcd2c | 2016-10-05 12:21:33 +1100 | [diff] [blame] | 44 | int error = vka_alloc_frame_at(vka, size_bits, paddr, frame); |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 45 | if (error) { |
Yu Hou | e9a9ff4 | 2019-07-18 17:26:01 +1000 | [diff] [blame] | 46 | ZF_LOGE("Failed to find frame at paddr %p", (void *)paddr); |
Anna Lyons | adbaab7 | 2016-03-29 13:59:06 +1100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | return error; |
| 50 | } |
| 51 | |
Yu Hou | e9a9ff4 | 2019-07-18 17:26:01 +1000 | [diff] [blame] | 52 | void *sel4platsupport_map_frame_at(vka_t *vka, vspace_t *vspace, uintptr_t paddr, size_t size_bits, vka_object_t *frame) |
Adrian Danis | 9f3238b | 2017-01-11 17:17:14 +1100 | [diff] [blame] | 53 | { |
| 54 | int error; |
| 55 | error = sel4platsupport_alloc_frame_at(vka, paddr, size_bits, frame); |
| 56 | if (error) { |
| 57 | return NULL; |
| 58 | } |
| 59 | void *vaddr = vspace_map_pages(vspace, &frame->cptr, &frame->ut, seL4_AllRights, 1, size_bits, 0); |
| 60 | if (!vaddr) { |
Yu Hou | e9a9ff4 | 2019-07-18 17:26:01 +1000 | [diff] [blame] | 61 | ZF_LOGE("Failed to map frame at paddr %p", (void *)paddr); |
Adrian Danis | 9f3238b | 2017-01-11 17:17:14 +1100 | [diff] [blame] | 62 | vka_free_object(vka, frame); |
| 63 | } |
| 64 | return vaddr; |
| 65 | } |