1// vi:set ft=cpp: -*- Mode: C++ -*-
2/* SPDX-License-Identifier: GPL-2.0-only or License-Ref-kk-custom */
4 * Copyright (C) 2014-2021 Kernkonzept GmbH.
5 * Author(s): Alexander Warg <alexander.warg@kernkonzept.com>
6 * Sarah Hoffmann <sarah.hoffmann@kernkonzept.com>
10#include <l4/drivers/hw_register_block>
11#include <l4/drivers/asm_access.h>
15class Mmio_register_block_base
22 explicit Mmio_register_block_base(l4_addr_t base = 0, l4_addr_t shift = 0)
23 : _base(base), _shift(shift) {}
25 template< typename T >
26 T read(l4_addr_t reg) const
27 { return Asm_access::read(reinterpret_cast<T const *>(_base + (reg << _shift))); }
29 template< typename T >
30 void write(T value, l4_addr_t reg) const
31 { Asm_access::write(value, reinterpret_cast<T *>(_base + (reg << _shift))); }
33 void set_base(l4_addr_t base) { _base = base; }
34 void set_shift(l4_addr_t shift) { _shift = shift; }
38 * An MMIO block with up to 64-bit register access (32-bit default) and little
41template< unsigned MAX_BITS = 32 >
42struct Mmio_register_block
43: Register_block_impl<Mmio_register_block<MAX_BITS>, MAX_BITS>,
44 Mmio_register_block_base
46 explicit Mmio_register_block(l4_addr_t base = 0, l4_addr_t shift = 0)
47 : Mmio_register_block_base(base, shift) {}