dma.cc 3.99 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.
 */

25
26
#include "sims/nic/corundum/dma.h"

Antoine Kaufmann's avatar
Antoine Kaufmann committed
27
28
#include <iostream>

Antoine Kaufmann's avatar
Antoine Kaufmann committed
29
#include "sims/nic/corundum/corundum.h"
30
#include "sims/nic/corundum/debug.h"
Antoine Kaufmann's avatar
Antoine Kaufmann committed
31
#include "sims/nic/corundum/mem.h"
Antoine Kaufmann's avatar
Antoine Kaufmann committed
32

33
34
35
36
37
38
39
40
41
42
43
44
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
45
46

#ifdef DMA_DEBUG
47
48
49
    std::cout << main_time << " dma[" << 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
50
#endif
Antoine Kaufmann's avatar
Antoine Kaufmann committed
51

52
53
    coord.dma_register(op, true);
  }
Antoine Kaufmann's avatar
Antoine Kaufmann committed
54

55
56
57
58
  p.dma_status_valid = 0;
  if (!completed.empty()) {
    DMAOp *op = completed.front();
    completed.pop_front();
Antoine Kaufmann's avatar
Antoine Kaufmann committed
59

60
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
    p.dma_status_valid = 1;
    p.dma_status_tag = op->tag;
    pending.erase(op);
    delete op;
  }
Antoine Kaufmann's avatar
Antoine Kaufmann committed
68
69
}

70
71
void DMAReader::pci_op_complete(DMAOp *op) {
  mw.op_issue(op);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
72
73
}

74
75
76
77
void DMAReader::mem_op_complete(DMAOp *op) {
  completed.push_back(op);
  // std::cout << "dma[" << label << "] mem complete " << op->dma_addr <<
  //      std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
78
}
Antoine Kaufmann's avatar
Antoine Kaufmann committed
79

80
81
82
83
84
85
86
87
88
89
90
91
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
92
93

#ifdef DMA_DEBUG
94
95
96
    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
97
#endif
Antoine Kaufmann's avatar
Antoine Kaufmann committed
98

99
100
101
    coord.dma_register(op, false);
    mr.op_issue(op);
  }
Antoine Kaufmann's avatar
Antoine Kaufmann committed
102

103
104
105
106
  p.dma_status_valid = 0;
  if (!completed.empty()) {
    DMAOp *op = completed.front();
    completed.pop_front();
Antoine Kaufmann's avatar
Antoine Kaufmann committed
107

Antoine Kaufmann's avatar
Antoine Kaufmann committed
108
#ifdef DMA_DEBUG
109
110
    std::cout << main_time << " dma write [" << label << "] status complete "
              << op->dma_addr << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
111
#endif
Antoine Kaufmann's avatar
Antoine Kaufmann committed
112

113
114
115
116
117
118
    p.dma_status_valid = 1;
    p.dma_status_tag = op->tag;
    pending.erase(op);
    // coord.msi_enqueue(0);
    delete op;
  }
Antoine Kaufmann's avatar
Antoine Kaufmann committed
119
120
}

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

129
void DMAWriter::mem_op_complete(DMAOp *op) {
Antoine Kaufmann's avatar
Antoine Kaufmann committed
130
#ifdef DMA_DEBUG
131
132
133
134
135
  std::cout << main_time << " dma write [" << label << "] mem complete "
            << op->dma_addr << ": ";
  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
136
#endif
137
  coord.dma_mark_ready(op);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
138
}