blob: 1c416d0a5e1e22ca82015c1d9b373de1c6dc50b8 [file] [log] [blame]
// Copyright 2016 The Fuchsia Authors
// Copyright (c) 2008 Travis Geiselbrecht
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT
#ifndef ZIRCON_KERNEL_INCLUDE_REG_H_
#define ZIRCON_KERNEL_INCLUDE_REG_H_
#include <lib/mmio-ptr/mmio-ptr.h>
#include <stdint.h>
// TODO(https://fxbug.dev/42170495): This is only used by old motmot and pl011 uart
// drivers, which are slated to be replaced. Remove this when they go.
#define REG32(addr) ((volatile uint32_t*)(uintptr_t)(addr))
// TODO(https://fxbug.dev/42072070): Remaining users should be migrated to more modern
// facilities such as hwreg or mmio-ptr directly.
inline void RMWREG32(volatile void* addr, unsigned int startbit, unsigned int width,
uint32_t value) {
MMIO_PTR volatile uint32_t* ptr =
reinterpret_cast<MMIO_PTR volatile uint32_t*>(reinterpret_cast<uintptr_t>(addr));
uint32_t reg = MmioRead32(ptr);
reg &= ~(((1 << width) - 1) << startbit);
reg |= (value << startbit);
MmioWrite32(reg, ptr);
}
inline uint32_t readl(uintptr_t addr) {
return MmioRead32(reinterpret_cast<MMIO_PTR volatile uint32_t*>(addr));
}
inline void writel(uint32_t value, uintptr_t addr) {
MmioWrite32(value, reinterpret_cast<MMIO_PTR volatile uint32_t*>(addr));
}
inline void writel(uint32_t value, volatile void* addr) {
writel(value, reinterpret_cast<uintptr_t>(addr));
}
#endif // ZIRCON_KERNEL_INCLUDE_REG_H_