1/* 2 * Copyright 2017, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(DATA61_BSD) 11 */ 12 13#include <autoconf.h> 14 15#include <stdio.h> 16#include <stdlib.h> 17#include <assert.h> 18 19#include <sel4/sel4.h> 20 21#include <simple-default/simple-default.h> 22 23#include <vspace/page.h> 24 25seL4_Error simple_default_get_irq(void *data, int irq, seL4_CNode root, seL4_Word index, uint8_t depth) 26{ 27 return seL4_IRQControl_Get(seL4_CapIRQControl, irq, root, index, depth); 28} 29 30seL4_Error simple_default_get_irq_trigger(void *data, int irq, int trigger, UNUSED int core, seL4_CNode root, 31 seL4_Word index, uint8_t depth) 32{ 33#if CONFIG_MAX_NUM_NODES > 1 34 return seL4_IRQControl_GetTriggerCore(seL4_CapIRQControl, irq, trigger, root, index, depth, core); 35#else 36 return seL4_IRQControl_GetTrigger(seL4_CapIRQControl, irq, trigger, root, index, depth); 37#endif 38} 39 40#ifdef CONFIG_TK1_SMMU 41seL4_Error simple_default_get_iospace_cap_count(void *data, int *count) 42{ 43 seL4_BootInfo *bi = data; 44 seL4_SlotRegion reg; 45 46 if (!bi) { 47 ZF_LOGE("BootInfo pointer is NULL"); 48 *count = 0; 49 return seL4_InvalidArgument; 50 } 51 52 reg = bi->ioSpaceCaps; 53 54 if (reg.end <= reg.start) { 55 ZF_LOGE("BootInfo for iospace caps is incorrect"); 56 *count = 0; 57 return seL4_InvalidArgument; 58 } 59 60 *count = reg.end - reg.start; 61 return seL4_NoError; 62} 63 64seL4_CPtr simple_default_get_iospace_nth_cap(void *data, int n) 65{ 66 seL4_BootInfo *bi = data; 67 seL4_SlotRegion reg; 68 seL4_CPtr cap; 69 70 if (!bi) { 71 ZF_LOGE("BootInfo pointer is NULL"); 72 return seL4_CapNull; 73 } 74 75 reg = bi->ioSpaceCaps; 76 77 if (reg.end <= reg.start) { 78 ZF_LOGE("BootInfo for iospace caps is incorrect"); 79 return seL4_CapNull; 80 } 81 82 cap = reg.start; 83 cap += n; 84 85 if (cap >= reg.end || cap < reg.start) { 86 ZF_LOGE("Invalid IOSpace cap"); 87 return seL4_CapNull; 88 } 89 90 return cap; 91} 92 93#endif 94 95void simple_default_init_arch_simple(arch_simple_t *simple, void *data) 96{ 97 simple->data = data; 98 simple->irq = simple_default_get_irq; 99 simple->irq_trigger = simple_default_get_irq_trigger; 100#ifdef CONFIG_TK1_SMMU 101 simple->iospace_cap_count = simple_default_get_iospace_cap_count; 102 simple->iospace_get_nth_cap = simple_default_get_iospace_nth_cap; 103#endif 104} 105