2 * Copyright (c) 2008 Mark D. Hill and David A. Wood
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "mem/protocol/SequencerMsg.hh"
30 #include "mem/protocol/SequencerRequestType.hh"
31 #include "mem/ruby/buffers/MessageBuffer.hh"
32 #include "mem/ruby/slicc_interface/AbstractController.hh"
33 #include "mem/ruby/system/DMASequencer.hh"
34 #include "mem/ruby/system/System.hh"
36 DMASequencer::DMASequencer(const Params
*p
)
46 m_data_block_mask
= ~ (~0 << RubySystem::getBlockSizeBits());
50 DMASequencer::makeRequest(const RubyRequest
&request
)
53 return RequestStatus_BufferFull
;
56 uint64_t paddr
= request
.paddr
;
57 uint8_t* data
= request
.data
;
58 int len
= request
.len
;
60 switch(request
.type
) {
61 case RubyRequestType_LD
:
64 case RubyRequestType_ST
:
67 case RubyRequestType_NULL
:
68 case RubyRequestType_IFETCH
:
69 case RubyRequestType_Load_Linked
:
70 case RubyRequestType_Store_Conditional
:
71 case RubyRequestType_RMW_Read
:
72 case RubyRequestType_RMW_Write
:
73 case RubyRequestType_Locked_RMW_Read
:
74 case RubyRequestType_Locked_RMW_Write
:
75 case RubyRequestType_NUM
:
76 panic("DMASequencer::makeRequest does not support RubyRequestType");
77 return RequestStatus_NULL
;
80 assert(!m_is_busy
); // only support one outstanding DMA request
83 active_request
.start_paddr
= paddr
;
84 active_request
.write
= write
;
85 active_request
.data
= data
;
86 active_request
.len
= len
;
87 active_request
.bytes_completed
= 0;
88 active_request
.bytes_issued
= 0;
89 active_request
.pkt
= request
.pkt
;
91 SequencerMsg
*msg
= new SequencerMsg
;
92 msg
->getPhysicalAddress() = Address(paddr
);
93 msg
->getLineAddress() = line_address(msg
->getPhysicalAddress());
94 msg
->getType() = write
? SequencerRequestType_ST
: SequencerRequestType_LD
;
95 int offset
= paddr
& m_data_block_mask
;
97 msg
->getLen() = (offset
+ len
) <= RubySystem::getBlockSizeBytes() ?
98 len
: RubySystem::getBlockSizeBytes() - offset
;
100 if (write
&& (data
!= NULL
)) {
101 if (active_request
.data
!= NULL
) {
102 msg
->getDataBlk().setData(data
, offset
, msg
->getLen());
106 assert(m_mandatory_q_ptr
!= NULL
);
107 m_mandatory_q_ptr
->enqueue(msg
);
108 active_request
.bytes_issued
+= msg
->getLen();
110 return RequestStatus_Issued
;
114 DMASequencer::issueNext()
116 assert(m_is_busy
== true);
117 active_request
.bytes_completed
= active_request
.bytes_issued
;
118 if (active_request
.len
== active_request
.bytes_completed
) {
120 // Must unset the busy flag before calling back the dma port because
121 // the callback may cause a previously nacked request to be reissued
123 DPRINTF(RubyDma
, "DMA request completed\n");
125 ruby_hit_callback(active_request
.pkt
);
129 SequencerMsg
*msg
= new SequencerMsg
;
130 msg
->getPhysicalAddress() = Address(active_request
.start_paddr
+
131 active_request
.bytes_completed
);
133 assert((msg
->getPhysicalAddress().getAddress() & m_data_block_mask
) == 0);
134 msg
->getLineAddress() = line_address(msg
->getPhysicalAddress());
136 msg
->getType() = (active_request
.write
? SequencerRequestType_ST
:
137 SequencerRequestType_LD
);
140 (active_request
.len
-
141 active_request
.bytes_completed
< RubySystem::getBlockSizeBytes() ?
142 active_request
.len
- active_request
.bytes_completed
:
143 RubySystem::getBlockSizeBytes());
145 if (active_request
.write
) {
147 setData(&active_request
.data
[active_request
.bytes_completed
],
149 msg
->getType() = SequencerRequestType_ST
;
151 msg
->getType() = SequencerRequestType_LD
;
154 assert(m_mandatory_q_ptr
!= NULL
);
155 m_mandatory_q_ptr
->enqueue(msg
);
156 active_request
.bytes_issued
+= msg
->getLen();
158 "DMA request bytes issued %d, bytes completed %d, total len %d\n",
159 active_request
.bytes_issued
, active_request
.bytes_completed
,
164 DMASequencer::dataCallback(const DataBlock
& dblk
)
166 assert(m_is_busy
== true);
167 int len
= active_request
.bytes_issued
- active_request
.bytes_completed
;
169 if (active_request
.bytes_completed
== 0)
170 offset
= active_request
.start_paddr
& m_data_block_mask
;
171 assert(active_request
.write
== false);
172 if (active_request
.data
!= NULL
) {
173 memcpy(&active_request
.data
[active_request
.bytes_completed
],
174 dblk
.getData(offset
, len
), len
);
180 DMASequencer::ackCallback()
186 DMASequencer::printConfig(std::ostream
& out
)
191 DMASequencerParams::create()
193 return new DMASequencer(this);