gem5  v20.1.0.0
hsa_driver.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2018 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * For use for simulation and test purposes only
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from this
19  * software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Authors: Anthony Gutierrez
34  * Eric van Tassell
35  */
36 
37 #include "dev/hsa/hsa_driver.hh"
38 
39 #include "cpu/thread_context.hh"
40 #include "debug/HSADriver.hh"
41 #include "dev/hsa/hsa_device.hh"
42 #include "dev/hsa/kfd_ioctl.h"
43 #include "params/HSADriver.hh"
44 #include "sim/process.hh"
45 #include "sim/proxy_ptr.hh"
46 #include "sim/syscall_emul_buf.hh"
47 
48 HSADriver::HSADriver(HSADriverParams *p)
49  : EmulatedDriver(p), device(p->device), queueId(0)
50 {
51 }
52 
56 int
57 HSADriver::open(ThreadContext *tc, int mode, int flags)
58 {
59  DPRINTF(HSADriver, "Opened %s\n", filename);
60  auto process = tc->getProcessPtr();
61  auto device_fd_entry = std::make_shared<DeviceFDEntry>(this, filename);
62  int tgt_fd = process->fds->allocFD(device_fd_entry);
63  return tgt_fd;
64 }
65 
70 Addr
71 HSADriver::mmap(ThreadContext *tc, Addr start, uint64_t length, int prot,
72  int tgt_flags, int tgt_fd, int offset)
73 {
74  DPRINTF(HSADriver, "amdkfd doorbell mmap (start: %p, length: 0x%x,"
75  "offset: 0x%x)\n", start, length, offset);
76 
77  auto process = tc->getProcessPtr();
78  auto mem_state = process->memState;
79 
80  // Extend global mmap region if necessary.
81  if (start == 0) {
82  // Assume mmap grows down, as in x86 Linux.
83  start = mem_state->getMmapEnd() - length;
84  mem_state->setMmapEnd(start);
85  }
86 
91  process->pTable->map(start, device->hsaPacketProc().pioAddr,
92  length, false);
93  DPRINTF(HSADriver, "amdkfd doorbell mapped to %xp\n", start);
94  return start;
95 }
96 
104 void
106 {
107  VPtr<kfd_ioctl_create_queue_args> args(ioc_buf, tc);
108 
109  if (queueId >= 0x1000) {
110  fatal("%s: Exceeded maximum number of HSA queues allowed\n", name());
111  }
112 
113  args->queue_id = queueId++;
114  auto &hsa_pp = device->hsaPacketProc();
116  args->ring_base_address, args->queue_id,
117  args->ring_size);
118 }
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
HSADriver::HSADriver
HSADriver(HSADriverParams *p)
Definition: hsa_driver.cc:48
HSADriver::mmap
Addr mmap(ThreadContext *tc, Addr start, uint64_t length, int prot, int tgtFlags, int tgtFd, int offset)
Currently, mmap() will simply setup a mapping for the associated device's packet processor's doorbell...
Definition: hsa_driver.cc:71
length
uint8_t length
Definition: inet.hh:422
kfd_ioctl_create_queue_args::read_pointer_address
uint64_t read_pointer_address
Definition: kfd_ioctl.h:48
hsa_driver.hh
EmulatedDriver::filename
const std::string & filename
filename for opening this driver (under /dev)
Definition: emul_driver.hh:58
ProxyPtr
Definition: proxy_ptr.hh:236
proxy_ptr.hh
ThreadContext::getProcessPtr
virtual Process * getProcessPtr()=0
syscall_emul_buf.hh
HSAPacketProcessor::pioAddr
Addr pioAddr
Definition: hsa_packet_processor.hh:306
HSAPacketProcessor::setDeviceQueueDesc
void setDeviceQueueDesc(uint64_t hostReadIndexPointer, uint64_t basePointer, uint64_t queue_id, uint32_t size)
Definition: hsa_packet_processor.cc:99
EmulatedDriver
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
Definition: emul_driver.hh:52
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
HSADriver::queueId
uint32_t queueId
Definition: hsa_driver.hh:75
kfd_ioctl_create_queue_args::ring_base_address
uint64_t ring_base_address
Definition: kfd_ioctl.h:46
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
kfd_ioctl_create_queue_args::queue_id
uint32_t queue_id
Definition: kfd_ioctl.h:56
process.hh
ArmISA::mode
Bitfield< 4, 0 > mode
Definition: miscregs_types.hh:70
X86ISA::prot
Bitfield< 7 > prot
Definition: misc.hh:582
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
HSADevice::hsaPacketProc
HSAPacketProcessor & hsaPacketProc()
Definition: hsa_device.cc:45
kfd_ioctl_create_queue_args::ring_size
uint32_t ring_size
Definition: kfd_ioctl.h:51
HSADriver
Definition: hsa_driver.hh:62
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
HSADriver::device
HSADevice * device
HSA agent (device) that is controled by this driver.
Definition: hsa_driver.hh:74
hsa_device.hh
HSADriver::allocateQueue
void allocateQueue(ThreadContext *tc, Addr ioc_buf)
Forward relevant parameters to packet processor; queueID is used to link doorbell.
Definition: hsa_driver.cc:105
kfd_ioctl.h
thread_context.hh
Process::memState
std::shared_ptr< MemState > memState
Definition: process.hh:279
HSADriver::open
int open(ThreadContext *tc, int mode, int flags)
Create an FD entry for the KFD inside of the owning process.
Definition: hsa_driver.cc:57
ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:153

Generated on Wed Sep 30 2020 14:02:11 for gem5 by doxygen 1.8.17