L4Re - L4 Runtime Environment
mmio_space
1 // -*- Mode: C++ -*-
2 // vim:ft=cpp
3 /*
4  * Copyright (C) 2017 Kernkonzept GmbH.
5  * Author(s): Sarah Hoffmann <sarah.hoffmann@kernkonzept.com>
6  *
7  * This file is distributed under the terms of the GNU General Public
8  * License, version 2. Please see the COPYING-GPL-2 file for details.
9  */
10 #pragma once
11 
12 #include <l4/re/protocols.h>
13 #include <l4/sys/capability>
14 #include <l4/sys/cxx/ipc_types>
15 #include <l4/sys/cxx/ipc_iface>
16 
17 namespace L4Re
18 {
19 
20 /**
21  * Interface for memory-like address space accessible via IPC.
22  *
23  * \includefile{l4/re/mmio_space}
24  */
25 struct L4_EXPORT Mmio_space
26 : public L4::Kobject_t<Mmio_space, L4::Kobject, L4RE_PROTO_MMIO_SPACE>
27 {
28  /// Actual size of the value to read or write.
29  enum Access_width
30  {
31  Wd_8bit = 0, ///< Value is a byte.
32  Wd_16bit = 1, ///< Value is a 2-byte word.
33  Wd_32bit = 2, ///< Value is a 4-byte word.
34  Wd_64bit = 3 ///< Value is a 8-byte word.
35  };
36 
37  /// Device address.
38  typedef l4_uint64_t Addr;
39 
40  /**
41  * Read a value from the given address.
42  *
43  * \param addr Device virtual address to read from. The address
44  * must be aligned relative to the access width.
45  * \param width Access width of value to be read, see #Access_width.
46  * \param[out] value Return value. If width is smaller than 64 bit,the
47  * upper bits are guaranteed to be 0.
48  *
49  * \retval #L4_EOK Success.
50  * \retval -L4_EPERM Insufficient read rights.
51  * \retval -L4_EINVAL Address does not exist or cannot be accessed
52  * with the given width.
53  */
54  L4_INLINE_RPC(long, mmio_read, (Addr addr, char width, l4_uint64_t *value));
55 
56  /**
57  * Write a value to the given address.
58  *
59  * \param addr Device virtual address to write to. The address
60  * must be aligned relative to the access width.
61  * \param width Access width of value to write, see #Access_width.
62  * \param value Value to write. If width is smaller than 64 bit,
63  * the upper bits are ignored.
64  *
65  * \retval #L4_EOK Success.
66  * \retval -L4_EPERM Insufficient write rights.
67  * \retval -L4_EINVAL Address does not exist or cannot be accessed
68  * with the given width.
69  */
70  L4_INLINE_RPC(long, mmio_write, (Addr addr, char width, l4_uint64_t value));
71 
72  typedef L4::Typeid::Rpcs<mmio_read_t, mmio_write_t> Rpcs;
73 };
74 
75 }