gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dma_virt_device.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "dev/dma_virt_device.hh"
33 
34 namespace gem5
35 {
36 
37 void
38 DmaVirtDevice::dmaReadVirt(Addr host_addr, unsigned size,
39  DmaCallback *cb, void *data, Tick delay)
40 {
41  dmaVirt(&DmaDevice::dmaRead, host_addr, size, cb, data, delay);
42 }
43 
44 void
45 DmaVirtDevice::dmaWriteVirt(Addr host_addr, unsigned size,
46  DmaCallback *cb, void *data, Tick delay)
47 {
48  dmaVirt(&DmaDevice::dmaWrite, host_addr, size, cb, data, delay);
49 }
50 
51 void
52 DmaVirtDevice::dmaVirt(DmaFnPtr dmaFn, Addr addr, unsigned size,
53  DmaCallback *cb, void *data, Tick delay)
54 {
55  if (size == 0) {
56  if (cb)
57  schedule(cb->getChunkEvent(), curTick() + delay);
58  return;
59  }
60 
61  // move the buffer data pointer with the chunks
62  uint8_t *loc_data = (uint8_t*)data;
63 
64  TranslationGenPtr gen = translate(addr, size);
65  for (const auto &range: *gen) {
66  fatal_if(range.fault, "Failed translation: vaddr 0x%x", range.vaddr);
67 
68  Event *event = cb ? cb->getChunkEvent() : nullptr;
69  (this->*dmaFn)(range.paddr, range.size, event, loc_data, delay);
70  loc_data += range.size;
71  }
72 }
73 
74 } // namespace gem5
gem5::curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::DmaVirtDevice::dmaReadVirt
void dmaReadVirt(Addr host_addr, unsigned size, DmaCallback *cb, void *data, Tick delay=0)
Initiate a DMA read from virtual address host_addr.
Definition: dma_virt_device.cc:38
gem5::DmaVirtDevice::dmaVirt
void dmaVirt(DmaFnPtr dmaFn, Addr host_addr, unsigned size, DmaCallback *cb, void *data, Tick delay=0)
Initiate a call to DmaDevice using DmaFnPtr do a DMA starting from virtual address host_addr for size...
Definition: dma_virt_device.cc:52
gem5::MipsISA::event
Bitfield< 10, 5 > event
Definition: pra_constants.hh:300
gem5::DmaDevice::dmaRead
void dmaRead(Addr addr, int size, Event *event, uint8_t *data, uint32_t sid, uint32_t ssid, Tick delay=0)
Definition: dma_device.hh:243
gem5::EventManager::schedule
void schedule(Event &event, Tick when)
Definition: eventq.hh:1012
gem5::DmaVirtDevice::translate
virtual TranslationGenPtr translate(Addr vaddr, Addr size)=0
Function used to translate a range of addresses from virtual to physical addresses.
gem5::DmaCallback::getChunkEvent
Event * getChunkEvent()
Request a chunk event.
Definition: dma_device.hh:328
gem5::Event
Definition: eventq.hh:254
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::DmaDevice::dmaWrite
void dmaWrite(Addr addr, int size, Event *event, uint8_t *data, uint32_t sid, uint32_t ssid, Tick delay=0)
Definition: dma_device.hh:229
gem5::DmaVirtDevice::dmaWriteVirt
void dmaWriteVirt(Addr host_addr, unsigned size, DmaCallback *b, void *data, Tick delay=0)
Initiate a DMA write from virtual address host_addr.
Definition: dma_virt_device.cc:45
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::DmaCallback
DMA callback class.
Definition: dma_device.hh:275
dma_virt_device.hh
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:236
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::TranslationGenPtr
std::unique_ptr< TranslationGen > TranslationGenPtr
Definition: translation_gen.hh:128
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Sun Jul 30 2023 01:56:55 for gem5 by doxygen 1.8.17