summaryrefslogtreecommitdiff
path: root/include/reg.h
blob: 321074b4ee6101a60cedb5f86fc8d4307a1d44b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * reg.h - mmio accessors. ld/st straight to the device, nothing cute.
 *
 * Copyright (C) 2026 Bradley Morgan <brads@mainlining.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef __REG_H
#define __REG_H

#include <sys/types.h>
#include <stdint.h>

#define REG32(addr) ((volatile uint32_t *)(uintptr_t)(addr))

static inline void writel(uint32_t v, volatile void *addr)
{
	*(volatile uint32_t *)addr = v;
}

static inline uint32_t readl(const volatile void *addr)
{
	return *(const volatile uint32_t *)addr;
}

static inline void writew(uint16_t v, volatile void *addr)
{
	*(volatile uint16_t *)addr = v;
}

static inline uint16_t readw(const volatile void *addr)
{
	return *(const volatile uint16_t *)addr;
}

static inline void writeb(uint8_t v, volatile void *addr)
{
	*(volatile uint8_t *)addr = v;
}

static inline uint8_t readb(const volatile void *addr)
{
	return *(const volatile uint8_t *)addr;
}

#endif