kvm, arm: Switch to the device EQ when accessing ISA devices
[gem5.git] / src / sim / emul_driver.hh
1 /*
2 * Copyright (c) 2014 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
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.
15 *
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.
27 *
28 * Author: Steve Reinhardt
29 */
30
31 #ifndef __SIM_EMUL_DRIVER_HH
32 #define __SIM_EMUL_DRIVER_HH
33
34 #include <string>
35
36 #include "params/EmulatedDriver.hh"
37 #include "sim/sim_object.hh"
38
39 class Process;
40 class ThreadContext;
41
42 /**
43 * EmulatedDriver is an abstract base class for fake SE-mode device drivers.
44 *
45 * Specific drivers that allow applications to communicate with simulated
46 * hardware inside gem5 can be created by deriving from this class and
47 * overriding the abstract virtual methods.
48 *
49 * Currently only open(), ioctl(), and mmap() calls are supported, but other
50 * calls (e.g., read(), write()) could be added as needed.
51 */
52 class EmulatedDriver : public SimObject
53 {
54 protected:
55 /**
56 * filename for opening this driver (under /dev)
57 */
58 const std::string &filename;
59
60 public:
61 EmulatedDriver(EmulatedDriverParams *p)
62 : SimObject(p), filename(p->filename)
63 {
64 }
65
66 /**
67 * Check for a match with this driver's filename.
68 */
69 bool match(const std::string &s) const { return (s == filename); }
70
71 /**
72 * Abstract method, invoked when the user program calls open() on
73 * the device driver. The parameters are the same as those passed
74 * to openFunc() (q.v.).
75 * @return A newly allocated target fd, or -1 on error.
76 */
77 virtual int open(Process *p, ThreadContext *tc,
78 int mode, int flags) = 0;
79
80 /**
81 * Abstract method, invoked when the user program calls ioctl() on
82 * the file descriptor returned by a previous open(). The parameters
83 * are the same as those passed in to ioctlFunc() (q.v.).
84 * @return The return code for the ioctl, or the negation of the errno
85 * (see the SyscallReturn class).
86 */
87 virtual int ioctl(Process *p, ThreadContext *tc, unsigned req) = 0;
88
89 /**
90 * Virtual method, invoked when the user program calls mmap() on
91 * the file descriptor returned by a previous open(). The parameters
92 * are the same as those passed in to mmapFunc() (q.v.).
93 * @return The return ptr for the mmap, or the negation of the errno
94 * (see the SyscallReturn class).
95 */
96 virtual Addr mmap(Process *p, ThreadContext *tc, Addr start,
97 uint64_t length, int prot, int tgtFlags, int tgtFd,
98 int offset) { return -EBADF; }
99 };
100
101 #endif // __SIM_EMUL_DRIVER_HH