Skip to content

Commit fd7ec12

Browse files
committed
[dma] Update pushSuperpage interface to block pushing of pages when dma stopped
1 parent 9d73aa8 commit fd7ec12

File tree

9 files changed

+25
-11
lines changed

9 files changed

+25
-11
lines changed

include/ReadoutCard/DmaChannelInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class DmaChannelInterface
6767
/// driver once it is pushed.
6868
///
6969
/// \param superpage Superpage to push
70-
virtual void pushSuperpage(Superpage superpage) = 0;
70+
virtual bool pushSuperpage(Superpage superpage) = 0;
7171

7272
/// Gets the superpage at the front of the "ready queue". Does not pop it.
7373
/// Note that it returns a copy of the Superpage's values.

src/Crorc/CrorcDmaChannel.cxx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,12 @@ auto CrorcDmaChannel::getSuperpage() -> Superpage
328328
return mReadyQueue.front();
329329
}
330330

331-
void CrorcDmaChannel::pushSuperpage(Superpage superpage)
331+
bool CrorcDmaChannel::pushSuperpage(Superpage superpage)
332332
{
333+
if (mDmaState != DmaState::STARTED) {
334+
return false;
335+
}
336+
333337
checkSuperpage(superpage);
334338

335339
if (mTransferQueue.size() >= TRANSFER_QUEUE_CAPACITY) {
@@ -347,6 +351,8 @@ void CrorcDmaChannel::pushSuperpage(Superpage superpage)
347351
mFreeFifoFront = (mFreeFifoFront + 1) % MAX_SUPERPAGE_DESCRIPTORS;
348352

349353
mTransferQueue.push_back(superpage);
354+
355+
return true;
350356
}
351357

352358
auto CrorcDmaChannel::popSuperpage() -> Superpage

src/Crorc/CrorcDmaChannel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
4949
virtual boost::optional<int32_t> getSerial() override;
5050
virtual boost::optional<std::string> getFirmwareInfo() override;
5151

52-
virtual void pushSuperpage(Superpage superpage) override;
52+
virtual bool pushSuperpage(Superpage superpage) override;
5353

5454
virtual int getTransferQueueAvailable() override;
5555
virtual int getReadyQueueSize() override;

src/Cru/CruDmaChannel.cxx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,12 @@ auto CruDmaChannel::getNextLinkIndex() -> LinkIndex
239239
return smallestQueueIndex;
240240
}
241241

242-
void CruDmaChannel::pushSuperpage(Superpage superpage)
242+
bool CruDmaChannel::pushSuperpage(Superpage superpage)
243243
{
244+
if (mDmaState != DmaState::STARTED) {
245+
return false;
246+
}
247+
244248
checkSuperpage(superpage);
245249

246250
if (mLinkQueuesTotalAvailable == 0) {
@@ -263,6 +267,8 @@ void CruDmaChannel::pushSuperpage(Superpage superpage)
263267
auto dmaPages = superpage.getSize() / mDmaPageSize;
264268
auto busAddress = getBusOffsetAddress(superpage.getOffset());
265269
getBar()->pushSuperpageDescriptor(link.id, dmaPages, busAddress);
270+
271+
return true;
266272
}
267273

268274
auto CruDmaChannel::getSuperpage() -> Superpage

src/Cru/CruDmaChannel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CruDmaChannel final : public DmaChannelPdaBase
4040

4141
virtual CardType::type getCardType() override;
4242

43-
virtual void pushSuperpage(Superpage) override;
43+
virtual bool pushSuperpage(Superpage) override;
4444

4545
virtual int getTransferQueueAvailable() override;
4646
virtual int getReadyQueueSize() override;

src/DmaChannelPdaBase.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ void DmaChannelPdaBase::startDma()
140140
// Checks DMA state and forwards call to subclass if necessary
141141
void DmaChannelPdaBase::stopDma()
142142
{
143+
mDmaState = DmaState::STOPPED;
143144
if (mDmaState == DmaState::UNKNOWN) {
144145
log("Unknown DMA state");
145146
} else if (mDmaState == DmaState::STOPPED) {
@@ -148,7 +149,6 @@ void DmaChannelPdaBase::stopDma()
148149
log("Stopping DMA", InfoLogger::InfoLogger::Debug);
149150
deviceStopDma();
150151
}
151-
mDmaState = DmaState::STOPPED;
152152
}
153153

154154
void DmaChannelPdaBase::resetChannel(ResetLevel::type resetLevel)

src/DmaChannelPdaBase.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,14 @@ class DmaChannelPdaBase : public DmaChannelBase
113113
return *(mRocPciDevice.get());
114114
}
115115

116+
protected:
117+
/// Current state of the DMA
118+
DmaState::type mDmaState;
119+
116120
private:
117121
/// Contains addresses & size of the buffer
118122
std::unique_ptr<DmaBufferProviderInterface> mBufferProvider;
119123

120-
/// Current state of the DMA
121-
DmaState::type mDmaState;
122-
123124
/// PDA device objects
124125
boost::scoped_ptr<RocPciDevice> mRocPciDevice;
125126
};

src/Dummy/DummyDmaChannel.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ boost::optional<std::string> DummyDmaChannel::getFirmwareInfo()
9898
return std::string("Dummy");
9999
}
100100

101-
void DummyDmaChannel::pushSuperpage(Superpage superpage)
101+
bool DummyDmaChannel::pushSuperpage(Superpage superpage)
102102
{
103103
if (getTransferQueueAvailable() == 0) {
104104
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("Could not push superpage, transfer queue was full"));
@@ -124,6 +124,7 @@ void DummyDmaChannel::pushSuperpage(Superpage superpage)
124124
}
125125

126126
mTransferQueue.push_back(superpage);
127+
return true;
127128
}
128129

129130
Superpage DummyDmaChannel::getSuperpage()

src/Dummy/DummyDmaChannel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DummyDmaChannel final : public DmaChannelBase
3737
DummyDmaChannel(const Parameters& parameters);
3838
virtual ~DummyDmaChannel();
3939

40-
virtual void pushSuperpage(Superpage) override;
40+
virtual bool pushSuperpage(Superpage) override;
4141
virtual Superpage getSuperpage() override;
4242
virtual Superpage popSuperpage() override;
4343
virtual void fillSuperpages() override;

0 commit comments

Comments
 (0)