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_IOAT_DMA_DEVICE_H
11#define LIB_IOAT_DMA_DEVICE_H
12
13/// forward declaration of the device
14struct ioat_dma_device;
15struct ioat_dma_channel;
16
17
18/**
19 * \brief pointer type conversion
20 */
21static inline struct ioat_dma_device *dma_device_to_ioat(struct dma_device *dev)
22{
23    return (struct ioat_dma_device *)dev;
24}
25
26
27/*
28 * ----------------------------------------------------------------------------
29 * device initialization / termination
30 * ----------------------------------------------------------------------------
31 */
32
33/**
34 * \brief initializes a IOAT DMA device with the giving capability
35 *
36 * \param mmio     capability representing the device's MMIO registers
37 * \param pci_addr the PCI address of this device
38 * \param dev      returns a pointer to the device structure
39 *
40 * \returns SYS_ERR_OK on success
41 *          errval on error
42 */
43errval_t ioat_dma_device_init(struct capref mmio,
44                              struct pci_addr *pci_addr,
45                              struct ioat_dma_device **dev);
46
47/**
48 * \brief terminates the device operation and frees up the allocated resources
49 *
50 * \param dev IOAT DMA device to shutdown
51 *
52 * \returns SYS_ERR_OK on success
53 *          errval on error
54 */
55errval_t ioat_dma_device_shutdown(struct ioat_dma_device *dev);
56
57/**
58 * \brief requests access to a IOAT DMA device from the IOAT device manager
59 *        and initializes the device.
60 *
61 * \param dev  returns a pointer to the device structure
62 *
63 * \returns SYS_ERR_OK on success
64 *          errval on error
65 */
66errval_t ioat_dma_device_acquire(struct ioat_dma_device **dev);
67
68/**
69 * \brief terminates the device operation and frees up the allocated resources
70 *        and releases the device and returns it to the IOAT device manager.
71 *
72 * \param dev IOAT DMA device to be released
73 *
74 * \returns SYS_ERR_OK on success
75 *          errval on error
76 */
77errval_t ioat_dma_device_release(struct ioat_dma_device *dev);
78
79
80/*
81 * ----------------------------------------------------------------------------
82 * Interrupt management
83 * ----------------------------------------------------------------------------
84 */
85
86/**
87 * \brief enables the interrupts for the device
88 *
89 * \param dev   IOAT DMA device
90 * \param type  interrupt type
91 * \param fn    interrupt handler function
92 * \param arg   argument supplied to the handler function
93 */
94errval_t ioat_dma_device_intr_enable(struct ioat_dma_device *dev,
95                                     dma_irq_t type,
96                                     dma_irq_fn_t fn,
97                                     void *arg);
98
99/**
100 * \brief disables the interrupts for the device
101 *
102 * \param dev   IOAT DMA device
103 */
104void ioat_dma_device_intr_disable(struct ioat_dma_device *dev);
105
106/**
107 * \brief sets the interrupt delay for the device
108 *
109 * \param dev   IOAT DMA device
110 * \param usec  interrupt delay in microseconds
111 */
112void ioat_dma_device_set_intr_delay(struct ioat_dma_device *dev,
113                                    uint16_t usec);
114
115/*
116 * ----------------------------------------------------------------------------
117 * Device Operation Functions
118 * ----------------------------------------------------------------------------
119 */
120
121
122/**
123 * \brief polls the channels of the IOAT DMA device
124 *
125 * \param dev   IOAT DMA device
126 *
127 * \returns SYS_ERR_OK on success
128 *          DMA_ERR_DEVICE_IDLE if there is nothing completed on the channels
129 *          errval on error
130 */
131errval_t ioat_dma_device_poll_channels(struct dma_device *dev);
132
133
134
135#endif  /* LIB_IOAT_DMA_DEVICE_H */
136