2012-01-09 12:29:03 +00:00
|
|
|
/*
|
2016-12-09 11:18:18 +00:00
|
|
|
* \brief Type-safe, fine-grained access to a continuous MMIO region
|
2012-01-09 12:29:03 +00:00
|
|
|
* \author Martin stein
|
|
|
|
* \date 2011-10-26
|
|
|
|
*/
|
|
|
|
|
2012-01-10 11:56:45 +00:00
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2011-2017 Genode Labs GmbH
|
2012-01-10 11:56:45 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2012-01-10 11:56:45 +00:00
|
|
|
*/
|
|
|
|
|
2012-07-10 08:23:05 +00:00
|
|
|
#ifndef _INCLUDE__UTIL__MMIO_H_
|
|
|
|
#define _INCLUDE__UTIL__MMIO_H_
|
2012-01-09 12:29:03 +00:00
|
|
|
|
2012-05-24 09:56:54 +00:00
|
|
|
/* Genode includes */
|
2016-12-09 11:18:18 +00:00
|
|
|
#include <util/register_set.h>
|
2012-01-09 12:29:03 +00:00
|
|
|
|
2016-12-09 11:18:18 +00:00
|
|
|
namespace Genode {
|
2015-03-04 20:12:14 +00:00
|
|
|
|
2016-12-09 11:18:18 +00:00
|
|
|
class Mmio_plain_access;
|
|
|
|
class Mmio;
|
|
|
|
}
|
2015-03-04 20:12:14 +00:00
|
|
|
|
|
|
|
/**
|
2016-12-09 11:18:18 +00:00
|
|
|
* Plain access implementation for MMIO
|
2015-03-04 20:12:14 +00:00
|
|
|
*/
|
2016-12-09 11:18:18 +00:00
|
|
|
class Genode::Mmio_plain_access
|
2012-01-09 12:29:03 +00:00
|
|
|
{
|
2016-12-09 11:18:18 +00:00
|
|
|
friend Register_set_plain_access;
|
2015-03-04 20:12:14 +00:00
|
|
|
|
2016-12-09 11:18:18 +00:00
|
|
|
private:
|
2012-01-09 12:29:03 +00:00
|
|
|
|
2017-03-06 12:56:33 +00:00
|
|
|
addr_t const _base;
|
2012-07-10 08:23:05 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/**
|
2016-12-09 11:18:18 +00:00
|
|
|
* Write '_ACCESS_T' typed 'value' to MMIO base + 'offset'
|
2015-03-04 20:12:14 +00:00
|
|
|
*/
|
2016-12-09 11:18:18 +00:00
|
|
|
template <typename ACCESS_T>
|
|
|
|
inline void _write(off_t const offset, ACCESS_T const value)
|
2015-03-04 20:12:14 +00:00
|
|
|
{
|
2017-03-06 12:56:33 +00:00
|
|
|
addr_t const dst = _base + offset;
|
2016-12-09 11:18:18 +00:00
|
|
|
*(ACCESS_T volatile *)dst = value;
|
2015-03-04 20:12:14 +00:00
|
|
|
}
|
2012-01-09 12:29:03 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/**
|
2016-12-09 11:18:18 +00:00
|
|
|
* Read '_ACCESS_T' typed from MMIO base + 'offset'
|
2015-03-04 20:12:14 +00:00
|
|
|
*/
|
2016-12-09 11:18:18 +00:00
|
|
|
template <typename ACCESS_T>
|
|
|
|
inline ACCESS_T _read(off_t const &offset) const
|
2015-03-04 20:12:14 +00:00
|
|
|
{
|
2017-03-06 12:56:33 +00:00
|
|
|
addr_t const dst = _base + offset;
|
2016-12-09 11:18:18 +00:00
|
|
|
ACCESS_T const value = *(ACCESS_T volatile *)dst;
|
|
|
|
return value;
|
2015-03-04 20:12:14 +00:00
|
|
|
}
|
2012-01-09 12:29:03 +00:00
|
|
|
|
2016-12-09 11:18:18 +00:00
|
|
|
public:
|
2012-07-03 11:06:29 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/**
|
2016-12-09 11:18:18 +00:00
|
|
|
* Constructor
|
2015-03-04 20:12:14 +00:00
|
|
|
*
|
2016-12-09 11:18:18 +00:00
|
|
|
* \param base base address of targeted MMIO region
|
2015-03-04 20:12:14 +00:00
|
|
|
*/
|
2017-03-06 12:56:33 +00:00
|
|
|
Mmio_plain_access(addr_t const base) : _base(base) { }
|
|
|
|
|
|
|
|
addr_t base() const { return _base; }
|
2016-12-09 11:18:18 +00:00
|
|
|
};
|
2015-03-04 20:12:14 +00:00
|
|
|
|
|
|
|
|
2016-12-09 11:18:18 +00:00
|
|
|
/**
|
|
|
|
* Type-safe, fine-grained access to a continuous MMIO region
|
|
|
|
*
|
|
|
|
* For further details refer to the documentation of the 'Register_set' class.
|
|
|
|
*/
|
|
|
|
struct Genode::Mmio : Mmio_plain_access, Register_set<Mmio_plain_access>
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \param base base address of targeted MMIO region
|
|
|
|
*/
|
|
|
|
Mmio(addr_t const base)
|
|
|
|
:
|
|
|
|
Mmio_plain_access(base),
|
|
|
|
Register_set(*static_cast<Mmio_plain_access *>(this)) { }
|
2015-03-04 20:12:14 +00:00
|
|
|
};
|
2012-01-09 12:29:03 +00:00
|
|
|
|
2012-07-10 08:23:05 +00:00
|
|
|
#endif /* _INCLUDE__UTIL__MMIO_H_ */
|