blob: 980ab7b42e8da42cc09a3cdc40c3069caec6fd23 [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
#include <lib/mmio-ptr/mmio-ptr.h>
#include <stdint.h>
// TODO( 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( 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));