dma.cpp 4.05 KB
Newer Older
Antoine Kaufmann's avatar
Antoine Kaufmann committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * Copyright 2021 Max Planck Institute for Software Systems, and
 * National University of Singapore
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

Antoine Kaufmann's avatar
Antoine Kaufmann committed
25
26
#include <iostream>

Antoine Kaufmann's avatar
Antoine Kaufmann committed
27
#include "debug.h"
Antoine Kaufmann's avatar
Antoine Kaufmann committed
28
29
30
31
#include "corundum.h"
#include "dma.h"
#include "mem.h"

Antoine Kaufmann's avatar
Antoine Kaufmann committed
32

Antoine Kaufmann's avatar
Antoine Kaufmann committed
33
34
35
36
37
38
39
40
41
42
43
44
45
void DMAReader::step()
{
    p.dma_ready = 1;
    if (p.dma_valid) {
        DMAOp *op = new DMAOp;
        op->engine = this;
        op->dma_addr = p.dma_addr;
        op->ram_sel = p.dma_ram_sel;
        op->ram_addr = p.dma_ram_addr;
        op->len = p.dma_len;
        op->tag = p.dma_tag;
        op->write = false;
        pending.insert(op);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
46
47

#ifdef DMA_DEBUG
48
        std::cout << main_time << " dma[" << label << "] op " << std::hex << op->dma_addr << " -> " <<
Antoine Kaufmann's avatar
Antoine Kaufmann committed
49
            op->ram_sel << ":" << op->ram_addr <<
Antoine Kaufmann's avatar
Antoine Kaufmann committed
50
51
            "   len=" << op->len << "   tag=" << (int) op->tag << std::endl;
#endif
Antoine Kaufmann's avatar
Antoine Kaufmann committed
52

Antoine Kaufmann's avatar
Antoine Kaufmann committed
53
        coord.dma_register(op, true);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
54
55
56
57
58
59
60
    }

    p.dma_status_valid = 0;
    if (!completed.empty()) {
        DMAOp *op = completed.front();
        completed.pop_front();

Antoine Kaufmann's avatar
Antoine Kaufmann committed
61
        //std::cout << "dma[" << label << "] status complete " << op->dma_addr << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

        p.dma_status_valid = 1;
        p.dma_status_tag = op->tag;
        pending.erase(op);
        delete op;
    }
}

void DMAReader::pci_op_complete(DMAOp *op)
{
    mw.op_issue(op);
}

void DMAReader::mem_op_complete(DMAOp *op)
{
    completed.push_back(op);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
78
    //std::cout << "dma[" << label << "] mem complete " << op->dma_addr << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
79
}
Antoine Kaufmann's avatar
Antoine Kaufmann committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95



void DMAWriter::step()
{
    p.dma_ready = 1;
    if (p.dma_valid) {
        DMAOp *op = new DMAOp;
        op->engine = this;
        op->dma_addr = p.dma_addr;
        op->ram_sel = p.dma_ram_sel;
        op->ram_addr = p.dma_ram_addr;
        op->len = p.dma_len;
        op->tag = p.dma_tag;
        op->write = true;
        pending.insert(op);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
96
97

#ifdef DMA_DEBUG
98
        std::cout << main_time << " dma write [" << label << "] op " << std::hex << op->dma_addr << " -> " <<
Antoine Kaufmann's avatar
Antoine Kaufmann committed
99
100
            op->ram_sel << ":" << op->ram_addr <<
            "   len=" << op->len << "   tag=" << (int) op->tag << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
101
#endif
Antoine Kaufmann's avatar
Antoine Kaufmann committed
102

Antoine Kaufmann's avatar
Antoine Kaufmann committed
103
        coord.dma_register(op, false);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
104
105
106
107
108
109
110
111
        mr.op_issue(op);
    }

    p.dma_status_valid = 0;
    if (!completed.empty()) {
        DMAOp *op = completed.front();
        completed.pop_front();

Antoine Kaufmann's avatar
Antoine Kaufmann committed
112
#ifdef DMA_DEBUG
113
        std::cout << main_time << " dma write [" << label << "] status complete " << op->dma_addr << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
114
#endif
Antoine Kaufmann's avatar
Antoine Kaufmann committed
115
116
117
118

        p.dma_status_valid = 1;
        p.dma_status_tag = op->tag;
        pending.erase(op);
119
        //coord.msi_enqueue(0);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
120
121
122
123
124
125
        delete op;
    }
}

void DMAWriter::pci_op_complete(DMAOp *op)
{
Antoine Kaufmann's avatar
Antoine Kaufmann committed
126
#ifdef DMA_DEBUG
127
    std::cout << main_time << " dma write [" << label << "] pci complete " << op->dma_addr << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
128
#endif
Antoine Kaufmann's avatar
Antoine Kaufmann committed
129
130
131
132
133
    completed.push_back(op);
}

void DMAWriter::mem_op_complete(DMAOp *op)
{
Antoine Kaufmann's avatar
Antoine Kaufmann committed
134
#ifdef DMA_DEBUG
135
    std::cout << main_time << " dma write [" << label << "] mem complete " << op->dma_addr << ": ";
136
137
138
    for (size_t i = 0; i < op->len; i++)
        std::cout << (unsigned) op->data[i] << " ";
    std::cout << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
139
140
#endif
    coord.dma_mark_ready(op);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
141
}