gem5  v20.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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/syscall_emul_buf.hh"
46 
47 HSADriver::HSADriver(HSADriverParams *p)
48  : EmulatedDriver(p), device(p->device), queueId(0)
49 {
50 }
51 
55 int
56 HSADriver::open(ThreadContext *tc, int mode, int flags)
57 {
58  DPRINTF(HSADriver, "Opened %s\n", filename);
59  auto process = tc->getProcessPtr();
60  auto device_fd_entry = std::make_shared<DeviceFDEntry>(this, filename);
61  int tgt_fd = process->fds->allocFD(device_fd_entry);
62  return tgt_fd;
63 }
64 
69 Addr
70 HSADriver::mmap(ThreadContext *tc, Addr start, uint64_t length, int prot,
71  int tgt_flags, int tgt_fd, int offset)
72 {
73  DPRINTF(HSADriver, "amdkfd doorbell mmap (start: %p, length: 0x%x,"
74  "offset: 0x%x)\n", start, length, offset);
75 
76  auto process = tc->getProcessPtr();
77  auto mem_state = process->memState;
78 
79  // Extend global mmap region if necessary.
80  if (start == 0) {
81  // Assume mmap grows down, as in x86 Linux.
82  start = mem_state->getMmapEnd() - length;
83  mem_state->setMmapEnd(start);
84  }
85 
90  process->pTable->map(start, device->hsaPacketProc().pioAddr,
91  length, false);
92  DPRINTF(HSADriver, "amdkfd doorbell mapped to %xp\n", start);
93  return start;
94 }
#define DPRINTF(x,...)
Definition: trace.hh:225
HSAPacketProcessor & hsaPacketProc()
Definition: hsa_device.cc:45
This file defines buffer classes used to handle pointer arguments in emulated syscalls.
virtual Process * getProcessPtr()=0
int open(ThreadContext *tc, int mode, int flags)
Create an FD entry for the KFD inside of the owning process.
Definition: hsa_driver.cc:56
Bitfield< 23, 0 > offset
Definition: types.hh:152
Bitfield< 4, 0 > mode
Bitfield< 7 > prot
Definition: misc.hh:582
std::shared_ptr< MemState > memState
Definition: process.hh:279
ThreadContext is the external interface to all thread state for anything outside of the CPU...
HSADevice * device
HSA agent (device) that is controled by this driver.
Definition: hsa_driver.hh:74
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
HSADriver(HSADriverParams *p)
Definition: hsa_driver.cc:47
const std::string & filename
filename for opening this driver (under /dev)
Definition: emul_driver.hh:58
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&#39;s packet processor&#39;s doorbell...
Definition: hsa_driver.cc:70
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
Definition: emul_driver.hh:52
uint8_t length
Definition: inet.hh:329
Bitfield< 0 > p
std::shared_ptr< FDArray > fds
Definition: process.hh:276
An HSADriver is an emulated driver that controls an HSA agent, or more simply put, an HSA device.

Generated on Thu May 28 2020 16:21:32 for gem5 by doxygen 1.8.13