1/*
2 * Copyright (c) 2014 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, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#ifndef LIB_DMA_SERVICE_H
11#define LIB_DMA_SERVICE_H
12
13/// dma service handle
14typedef struct dma_svc_st* dma_svc_handle_t;
15
16/**
17 * DMA service callbacks called when the message event occurs
18 * if a callback is not set, this will trigger a not supported
19 * error in the client.
20 */
21struct dma_service_cb
22{
23    /** informs about the new connection on the service */
24    errval_t (*connect)(void *arg, void **user_st);
25
26    /** registers a memory region to be used */
27    errval_t (*addregion)(dma_svc_handle_t svc_handle,
28                          struct capref cap);
29
30    /** deregisters a memory region*/
31    errval_t (*removeregion)(dma_svc_handle_t svc_handle,
32                             struct capref cap);
33
34    /** execute a memcpy request */
35    errval_t (*memcpy)(dma_svc_handle_t svc_handle,
36                       lpaddr_t dst,
37                       lpaddr_t src,
38                       size_t bytes,
39                       dma_req_id_t *id);
40};
41
42/**
43 * \brief initializes the DMA service and registers with the DMA manager
44 *
45 * \param cb        Callback function pointers
46 * \param arg       Argument passed to the connect callback
47 * \param svc_iref  Returns the exported iref
48 *
49 * \returns SYS_ERR_OK on success
50 *          errval on error
51 */
52errval_t dma_service_init(struct dma_service_cb *cb,
53                          void *arg,
54                          iref_t *svc_iref);
55
56/**
57 * \brief initializes the DMA service and exports it to the nameservice
58 *
59 * \param svc_name  The name of the service for nameservice registration
60 * \param cb        Callback function pointers
61 * \param arg       Argument passed to the connect callback
62 * \param svc_iref  Returns the exported iref
63 *
64 * \returns SYS_ERR_OK on success
65 *          errval on error
66 */
67errval_t dma_service_init_with_name(char *svc_name,
68                                    struct dma_service_cb *cb,
69                                    void *arg,
70                                    iref_t *svc_iref);
71
72/**
73 * \brief sends a done notification about the transfer that has completed
74 *
75 * \param binding   DMA binding
76 * \param err       Outcome of the transfer
77 * \param id        The id of the completed transfer
78 *
79 * \returns SYS_ERR_OK on success
80 *          errval on error
81 */
82errval_t dma_service_send_done(dma_svc_handle_t svc_handle,
83                               errval_t err,
84                               dma_req_id_t id);
85
86static inline void *dma_service_get_user_state(dma_svc_handle_t handle)
87{
88    return (void *) *((lvaddr_t *)handle);
89}
90
91#endif  /* LIB_DMA_CLIENT_H */
92