"PTDN/configs/ppocr_sys_mobile_params.txt" did not exist on "08166b8351da1b164a9e93fe140678b3e8bf4712"
dma.cpp 4.19 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
28
29
30
#include "sims/nic/corundum/debug.h"
#include "sims/nic/corundum/corundum.h"
#include "sims/nic/corundum/dma.h"
#include "sims/nic/corundum/mem.h"
Antoine Kaufmann's avatar
Antoine Kaufmann committed
31

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
Antoine Kaufmann's avatar
Antoine Kaufmann committed
48
49
        std::cout << main_time << " dma[" << label << "] op " << std::hex <<
            op->dma_addr << " -> " << 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
62
        // std::cout << "dma[" << label << "] status complete " << op->dma_addr
        //      << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

        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
79
80
    // std::cout << "dma[" << label << "] mem complete " << op->dma_addr <<
    //      std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
81
}
Antoine Kaufmann's avatar
Antoine Kaufmann committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97



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
98
99

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

Antoine Kaufmann's avatar
Antoine Kaufmann committed
106
        coord.dma_register(op, false);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
107
108
109
110
111
112
113
114
        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
115
#ifdef DMA_DEBUG
Antoine Kaufmann's avatar
Antoine Kaufmann committed
116
117
        std::cout << main_time << " dma write [" << label <<
            "] status complete " << op->dma_addr << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
118
#endif
Antoine Kaufmann's avatar
Antoine Kaufmann committed
119
120
121
122

        p.dma_status_valid = 1;
        p.dma_status_tag = op->tag;
        pending.erase(op);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
123
        // coord.msi_enqueue(0);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
124
125
126
127
128
129
        delete op;
    }
}

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

void DMAWriter::mem_op_complete(DMAOp *op)
{
Antoine Kaufmann's avatar
Antoine Kaufmann committed
139
#ifdef DMA_DEBUG
Antoine Kaufmann's avatar
Antoine Kaufmann committed
140
141
    std::cout << main_time << " dma write [" << label << "] mem complete " <<
        op->dma_addr << ": ";
142
143
144
    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
145
146
#endif
    coord.dma_mark_ready(op);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
147
}