1/* 2 * Copyright 2016, 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(D61_BSD) 11 */ 12 13#include <stdio.h> 14#include <stdlib.h> 15#include <string.h> 16#include <refos-util/cspace.h> 17#include <refos/vmlayout.h> 18#include <refos/refos.h> 19#include <refos-io/stdio.h> 20#include <refos-rpc/proc_client.h> 21#include <refos-rpc/proc_client_helper.h> 22#include <refos-rpc/name_client.h> 23#include <refos-rpc/name_client_helper.h> 24#include "state.h" 25#include "badge.h" 26 27/*! @file 28 @brief timer server global state & helper functions. */ 29 30struct timeserv_state timeServ; 31srv_common_t *timeServCommon; 32const char* dprintfServerName = "TIMESERV"; 33int dprintfServerColour = 34; 34 35static seL4_CPtr 36timeserv_get_irq_handler_endpoint(void *cookie, int irq) 37{ 38 return proc_get_irq_handler(irq); 39} 40 41void 42timeserv_init(void) 43{ 44 /* Initialise device IO manager. */ 45 dprintf(" Initialising timeserv device IO manager...\n"); 46 devio_init(&timeServ.devIO); 47 48 /* Set up the server common config. */ 49 srv_common_config_t cfg = { 50 .maxClients = SRV_DEFAULT_MAX_CLIENTS, 51 .clientBadgeBase = TIMESERV_CLIENT_BADGE_BASE, 52 .clientMagic = TIMESERV_CLIENT_MAGIC, 53 .notificationBufferSize = SRV_DEFAULT_NOTIFICATION_BUFFER_SIZE, 54 .paramBufferSize = SRV_DEFAULT_PARAM_BUFFER_SIZE, 55 .serverName = "timeserver", 56 .mountPointPath = TIMESERV_MOUNTPOINT, 57 .nameServEP = REFOS_NAMESERV_EP, 58 .faultDeathNotifyBadge = TIMESERV_ASYNC_NOTIFY_BADGE | TIMESERV_ASYNC_BADGE_MASK 59 }; 60 61 /* Set up file server common state. */ 62 timeServCommon = &timeServ.commonState; 63 srv_common_init(timeServCommon, cfg); 64 65 /* Set up irq handler state config. */ 66 dev_irq_config_t irqConfig = { 67 .numIRQChannels = TIMESERV_IRQ_BADGE_NCHANNELS, 68 .badgeBaseBit = TIMESERV_IRQ_BADGE_BASE_POW, 69 .badgeTopBit = TIMESERV_IRQ_BADGE_BASE_POW_TOP, 70 .badgeMaskBits = TIMESERV_ASYNC_BADGE_MASK, 71 .notifyAsyncEP = timeServCommon->notifyAsyncEP, 72 .getIRQHandlerEndpoint = timeserv_get_irq_handler_endpoint, 73 .getIRQHandlerEndpointCookie = NULL 74 }; 75 76 /* Set up IRQ handler state. */ 77 dev_irq_init(&timeServ.irqState, irqConfig); 78 assert(timeServ.irqState.magic == DEVICE_IRQ_MAGIC); 79 80 /* Create the badged EP to represent the timer dataspace. */ 81 timeServ.timerBadgeEP = srv_mint(TIMESERV_DSPACE_BADGE_TIMER, timeServCommon->anonEP); 82 assert(timeServ.timerBadgeEP); 83 84 /* Set up timer device. */ 85 device_timer_init(&timeServ.devTimer, &timeServ.devIO); 86}