1/* 2 * Copyright (c) 2016, ETH Zurich. 3 * All rights reserved. 4 * 5 * This file is distributed under the terms in the attached LICENSE file. 6 * If you do not find this file, copies can be found by writing to: 7 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group. 8 */ 9 10#include <stdlib.h> 11#include <stdio.h> 12#include <string.h> 13#include <assert.h> 14 15#include <barrelfish/barrelfish.h> 16#include <driverkit/driverkit.h> 17#include <driverkit/iommu.h> 18 19#include "queue_manager.h" 20 21#define DRIVER_DEBUG(x...) debug_printf("[ioat] " x) 22 23 24/** 25 * Driver initialization function. This function is called by the driver domain 26 * (see also 'create_handler' in ddomain_service.c). 27 * Typically through a request from the device manager. 28 * 29 * The init function is supposed to set `dev` to the exported service iref. 30 * The init function may use `bfi->dstate` to store additional state about the device. 31 * 32 * \param[in] bfi The instance of this driver. 33 * \param[in] name The name of this driver instance. 34 * \param[in] flags Additional flags (The exact flags supported is device/driver specific). 35 * \param[in] c Capabilities (for registers etc.) as provided by the device manager. 36 * The exact layout of the `c` is device specific. 37 * \param[out] dev The service iref over which the device can be contacted. 38 * 39 * \retval SYS_ERR_OK Device initialized successfully. 40 * \retval LIB_ERR_MALLOC_FAIL Unable to allocate memory for the driver. 41 */ 42static errval_t init(struct bfdriver_instance* bfi, const char* name, uint64_t flags, 43 struct capref* caps, size_t caps_len, char** args, size_t args_len, iref_t* dev) { 44 errval_t err; 45 46 47 DRIVER_DEBUG("%s:%d: %s\n", __FUNCTION__, __LINE__, bfi->driver->name); 48 49 /* TODO: obtain these values */ 50 struct capref devcap = NULL_CAP; 51 uint64_t id = 0x0; 52 53 /* */ 54 struct device_queue *q = calloc(1, sizeof(*q)); 55 if (q == NULL) { 56 return LIB_ERR_MALLOC_FAIL; 57 } 58 59 err = dqm_init_queue(devcap, id, QUEUE_TYPE_IOAT_DMA, q); 60 if (err_is_fail(err)) { 61 return err; 62 } 63 64 65 err = dqm_add_queue(q); 66 assert(err_is_ok(err)); 67 68 69 // 1. Initialize the device: 70 71 // 2. Export service to talk to the device: 72 73 // 3. Set iref of your exported service (this is reported back to Kaluga) 74 *dev = 0x00; 75 76 return SYS_ERR_OK; 77} 78 79/** 80 * Instructs driver to attach to the device. 81 * This function is only called if the driver has previously detached 82 * from the device (see also detach). 83 * 84 * \note After detachment the driver can not assume anything about the 85 * configuration of the device. 86 * 87 * \param[in] bfi The instance of this driver. 88 * \retval SYS_ERR_OK Device initialized successfully. 89 */ 90static errval_t attach(struct bfdriver_instance* bfi) { 91 DRIVER_DEBUG("%s:%d: %s\n", __FUNCTION__, __LINE__, bfi->driver->name); 92 93 return SYS_ERR_OK; 94} 95 96/** 97 * Instructs driver to detach from the device. 98 * The driver must yield any control over to the device after this function returns. 99 * The device may be left in any state. 100 * 101 * \param[in] bfi The instance of this driver. 102 * \retval SYS_ERR_OK Device initialized successfully. 103 */ 104static errval_t detach(struct bfdriver_instance* bfi) { 105 DRIVER_DEBUG("%s:%d: %s\n", __FUNCTION__, __LINE__, bfi->driver->name); 106 107 return SYS_ERR_OK; 108} 109 110/** 111 * Instructs the driver to go in a particular sleep state. 112 * Supported states are platform/device specific. 113 * 114 * \param[in] bfi The instance of this driver. 115 * \retval SYS_ERR_OK Device initialized successfully. 116 */ 117static errval_t set_sleep_level(struct bfdriver_instance* bfi, uint32_t level) { 118 DRIVER_DEBUG("%s:%d: %s\n", __FUNCTION__, __LINE__, bfi->driver->name); 119 120 121 return SYS_ERR_OK; 122} 123 124/** 125 * Destroys this driver instance. The driver will yield any 126 * control over the device and free any state allocated. 127 * 128 * \param[in] bfi The instance of this driver. 129 * \retval SYS_ERR_OK Device initialized successfully. 130 */ 131static errval_t destroy(struct bfdriver_instance* bfi) { 132 DRIVER_DEBUG("%s:%d: %s\n", __FUNCTION__, __LINE__, bfi->driver->name); 133 134 return SYS_ERR_OK; 135} 136 137/** 138 * Registers the driver module with the system. 139 * 140 * To link this particular module in your driver domain, 141 * add it to the addModules list in the Hakefile. 142 */ 143DEFINE_MODULE(ioat, init, attach, detach, set_sleep_level, destroy); 144