L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
hw_mmio_register_block
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/* SPDX-License-Identifier: GPL-2.0-only or License-Ref-kk-custom */
3/*
4 * Copyright (C) 2014-2021 Kernkonzept GmbH.
5 * Author(s): Alexander Warg <alexander.warg@kernkonzept.com>
6 * Sarah Hoffmann <sarah.hoffmann@kernkonzept.com>
7 */
8#pragma once
9
10#include <l4/drivers/hw_register_block>
11#include <l4/drivers/asm_access.h>
12
13namespace L4drivers {
14
15class Mmio_register_block_base
16{
17protected:
18 l4_addr_t _base;
19 l4_addr_t _shift;
20
21public:
22 explicit Mmio_register_block_base(l4_addr_t base = 0, l4_addr_t shift = 0)
23 : _base(base), _shift(shift) {}
24
25 template< typename T >
26 T read(l4_addr_t reg) const
27 { return Asm_access::read(reinterpret_cast<T const *>(_base + (reg << _shift))); }
28
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))); }
32
33 void set_base(l4_addr_t base) { _base = base; }
34 void set_shift(l4_addr_t shift) { _shift = shift; }
35};
36
37/**
38 * An MMIO block with up to 64-bit register access (32-bit default) and little
39 * endian byte order.
40 */
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
45{
46 explicit Mmio_register_block(l4_addr_t base = 0, l4_addr_t shift = 0)
47 : Mmio_register_block_base(base, shift) {}
48};
49
50}