From f0564a9c44b79e9bfb1001f887348a653f7b7d56 Mon Sep 17 00:00:00 2001 From: Michael Niewöhner Date: Sun, 3 Nov 2019 10:26:04 +0100 Subject: include: introduce update* for mmio operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce update* as equivalent of pci_update* for mmio operations. Change-Id: I9f188d586c09ee9f1e17290563f68970603204fb Signed-off-by: Michael Niewöhner Reviewed-on: https://review.coreboot.org/c/coreboot/+/36596 Reviewed-by: Aaron Durbin Tested-by: build bot (Jenkins) --- src/include/mmio.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/include/mmio.h diff --git a/src/include/mmio.h b/src/include/mmio.h new file mode 100644 index 0000000000..4f2c806cac --- /dev/null +++ b/src/include/mmio.h @@ -0,0 +1,45 @@ +/* + * This file is part of the coreboot project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +/* + * mmio.h provides update*() as well as read/write*() from arch/mmio.h + */ + +#ifndef __MMIO_H__ +#define __MMIO_H__ + +#include +#include + +static __always_inline void update8(volatile void *addr, uint8_t mask, uint8_t or) +{ + uint8_t reg = read8(addr); + reg = (reg & mask) | or; + write8(addr, reg); +} + +static __always_inline void update16(volatile void *addr, uint16_t mask, uint16_t or) +{ + uint16_t reg = read16(addr); + reg = (reg & mask) | or; + write16(addr, reg); +} + +static __always_inline void update32(volatile void *addr, uint32_t mask, uint32_t or) +{ + uint32_t reg = read32(addr); + reg = (reg & mask) | or; + write32(addr, reg); +} + +#endif /* __MMIO_H__ */ -- cgit v1.2.3