akaros/kern/include/mmio.h
<<
>>
Prefs
   1/* Generic I/O port emulation, based on MN10300 code
   2 *
   3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
   4 * Written by David Howells (dhowells@redhat.com)
   5 *
   6 * This program is free software; you can redistribute it and/or
   7 * modify it under the terms of the GNU General Public Licence
   8 * as published by the Free Software Foundation; either version
   9 * 2 of the Licence, or (at your option) any later version.
  10 *
  11 * Modified for Akaros (mostly just trimmed down and change b->8, w->16, etc).
  12 * Arches can't override these either.  I'm undecided about void* vs uintptr_t
  13 * for the addr parameter.
  14 */
  15
  16#pragma once
  17
  18#include <sys/types.h>
  19#include <endian.h>
  20
  21#define __iomem
  22#define __force
  23
  24/*
  25 * __raw_{read,write}{8,16,32,64}() access memory in native endianness.
  26 *
  27 * On some architectures memory mapped IO needs to be accessed differently.
  28 * On the simple architectures, we just read/write the memory location
  29 * directly.
  30 */
  31static inline uint8_t __raw_read8(const volatile uint8_t __iomem *addr)
  32{
  33        return *(const volatile uint8_t __force *)addr;
  34}
  35
  36static inline uint16_t __raw_read16(const volatile uint16_t __iomem *addr)
  37{
  38        return *(const volatile uint16_t __force *)addr;
  39}
  40
  41static inline uint32_t __raw_read32(const volatile uint32_t __iomem *addr)
  42{
  43        return *(const volatile uint32_t __force *)addr;
  44}
  45
  46static inline uint64_t __raw_read64(const volatile uint64_t __iomem *addr)
  47{
  48        return *(const volatile uint64_t __force *)addr;
  49}
  50
  51static inline void __raw_write8(uint8_t value, volatile uint8_t __iomem *addr)
  52{
  53        *(volatile uint8_t __force *)addr = value;
  54}
  55
  56static inline void __raw_write16(uint16_t value,
  57                                 volatile uint16_t __iomem *addr)
  58{
  59        *(volatile uint16_t __force *)addr = value;
  60}
  61
  62static inline void __raw_write32(uint32_t value,
  63                                 volatile uint32_t __iomem *addr)
  64{
  65        *(volatile uint32_t __force *)addr = value;
  66}
  67
  68static inline void __raw_write64(uint64_t value,
  69                                 volatile uint64_t __iomem *addr)
  70{
  71        *(volatile uint64_t __force *)addr = value;
  72}
  73
  74/*
  75 * {read,write}{8,16,32,64}() access little endian memory and return result in
  76 * native endianness.
  77 */
  78static inline uint8_t read8(const volatile uint8_t __iomem *addr)
  79{
  80        return __raw_read8(addr);
  81}
  82
  83static inline uint16_t read16(const volatile uint16_t __iomem *addr)
  84{
  85        return le16_to_cpu(__raw_read16(addr));
  86}
  87
  88static inline uint32_t read32(const volatile uint32_t __iomem *addr)
  89{
  90        return le32_to_cpu(__raw_read32(addr));
  91}
  92
  93static inline uint64_t read64(const volatile uint64_t __iomem *addr)
  94{
  95        return le64_to_cpu(__raw_read64(addr));
  96}
  97
  98static inline void write8(uint8_t value, volatile uint8_t __iomem *addr)
  99{
 100        __raw_write8(value, addr);
 101}
 102
 103static inline void write16(uint16_t value, volatile uint16_t __iomem *addr)
 104{
 105        __raw_write16(cpu_to_le16(value), addr);
 106}
 107
 108static inline void write32(uint32_t value, volatile uint32_t __iomem *addr)
 109{
 110        __raw_write32(cpu_to_le32(value), addr);
 111}
 112
 113static inline void write64(uint64_t value, volatile uint64_t __iomem *addr)
 114{
 115        __raw_write64(cpu_to_le64(value), addr);
 116}
 117