dma.cpp 2.66 KB
Newer Older
Antoine Kaufmann's avatar
Antoine Kaufmann committed
1
2
#include <iostream>

Antoine Kaufmann's avatar
Antoine Kaufmann committed
3
#include "debug.h"
Antoine Kaufmann's avatar
Antoine Kaufmann committed
4
5
6
7
#include "corundum.h"
#include "dma.h"
#include "mem.h"

Antoine Kaufmann's avatar
Antoine Kaufmann committed
8

Antoine Kaufmann's avatar
Antoine Kaufmann committed
9
10
11
12
13
14
15
16
17
18
19
20
21
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
22
23
24

#ifdef DMA_DEBUG
        std::cout << "dma[" << label << "] op " << op->dma_addr << " -> " <<
Antoine Kaufmann's avatar
Antoine Kaufmann committed
25
            op->ram_sel << ":" << op->ram_addr <<
Antoine Kaufmann's avatar
Antoine Kaufmann committed
26
27
            "   len=" << op->len << "   tag=" << (int) op->tag << std::endl;
#endif
Antoine Kaufmann's avatar
Antoine Kaufmann committed
28

Antoine Kaufmann's avatar
Antoine Kaufmann committed
29
        coord.dma_register(op, true);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
30
31
32
33
34
35
36
    }

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

Antoine Kaufmann's avatar
Antoine Kaufmann committed
37
        //std::cout << "dma[" << label << "] status complete " << op->dma_addr << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

        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
54
    //std::cout << "dma[" << label << "] mem complete " << op->dma_addr << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
55
}
Antoine Kaufmann's avatar
Antoine Kaufmann committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71



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
72
73

#ifdef DMA_DEBUG
Antoine Kaufmann's avatar
Antoine Kaufmann committed
74
75
76
        std::cout << "dma write [" << label << "] op " << 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
77
#endif
Antoine Kaufmann's avatar
Antoine Kaufmann committed
78

Antoine Kaufmann's avatar
Antoine Kaufmann committed
79
        coord.dma_register(op, false);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
80
81
82
83
84
85
86
87
        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
88
#ifdef DMA_DEBUG
Antoine Kaufmann's avatar
Antoine Kaufmann committed
89
        std::cout << "dma write [" << label << "] status complete " << op->dma_addr << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
90
#endif
Antoine Kaufmann's avatar
Antoine Kaufmann committed
91
92
93
94
95
96
97
98
99
100

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

void DMAWriter::pci_op_complete(DMAOp *op)
{
Antoine Kaufmann's avatar
Antoine Kaufmann committed
101
#ifdef DMA_DEBUG
Antoine Kaufmann's avatar
Antoine Kaufmann committed
102
    std::cout << "dma write [" << label << "] pci complete " << op->dma_addr << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
103
#endif
Antoine Kaufmann's avatar
Antoine Kaufmann committed
104
105
106
107
108
    completed.push_back(op);
}

void DMAWriter::mem_op_complete(DMAOp *op)
{
Antoine Kaufmann's avatar
Antoine Kaufmann committed
109
#ifdef DMA_DEBUG
Antoine Kaufmann's avatar
Antoine Kaufmann committed
110
    std::cout << "dma write [" << label << "] mem complete " << op->dma_addr << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
111
112
#endif
    coord.dma_mark_ready(op);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
113
}