linux/arch/hexagon/include/asm/io.h
<<
>>
Prefs
   1/*
   2 * IO definitions for the Hexagon architecture
   3 *
   4 * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
   5 *
   6 * This program is free software; you can redistribute it and/or modify
   7 * it under the terms of the GNU General Public License version 2 and
   8 * only version 2 as published by the Free Software Foundation.
   9 *
  10 * This program is distributed in the hope that it will be useful,
  11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13 * GNU General Public License for more details.
  14 *
  15 * You should have received a copy of the GNU General Public License
  16 * along with this program; if not, write to the Free Software
  17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18 * 02110-1301, USA.
  19 */
  20
  21#ifndef _ASM_IO_H
  22#define _ASM_IO_H
  23
  24#ifdef __KERNEL__
  25
  26#include <linux/types.h>
  27#include <linux/delay.h>
  28#include <linux/vmalloc.h>
  29#include <asm/string.h>
  30#include <asm/mem-layout.h>
  31#include <asm/iomap.h>
  32#include <asm/page.h>
  33#include <asm/cacheflush.h>
  34#include <asm/tlbflush.h>
  35
  36/*
  37 * We don't have PCI yet.
  38 * _IO_BASE is pointing at what should be unused virtual space.
  39 */
  40#define IO_SPACE_LIMIT 0xffff
  41#define _IO_BASE ((void __iomem *)0xfe000000)
  42
  43#define IOMEM(x)        ((void __force __iomem *)(x))
  44
  45extern int remap_area_pages(unsigned long start, unsigned long phys_addr,
  46                                unsigned long end, unsigned long flags);
  47
  48extern void __iounmap(const volatile void __iomem *addr);
  49
  50/* Defined in lib/io.c, needed for smc91x driver. */
  51extern void __raw_readsw(const void __iomem *addr, void *data, int wordlen);
  52extern void __raw_writesw(void __iomem *addr, const void *data, int wordlen);
  53
  54extern void __raw_readsl(const void __iomem *addr, void *data, int wordlen);
  55extern void __raw_writesl(void __iomem *addr, const void *data, int wordlen);
  56
  57#define readsw(p, d, l) __raw_readsw(p, d, l)
  58#define writesw(p, d, l) __raw_writesw(p, d, l)
  59
  60#define readsl(p, d, l)   __raw_readsl(p, d, l)
  61#define writesl(p, d, l)  __raw_writesl(p, d, l)
  62
  63/*
  64 * virt_to_phys - map virtual address to physical
  65 * @address:  address to map
  66 */
  67static inline unsigned long virt_to_phys(volatile void *address)
  68{
  69        return __pa(address);
  70}
  71
  72/*
  73 * phys_to_virt - map physical address to virtual
  74 * @address: address to map
  75 */
  76static inline void *phys_to_virt(unsigned long address)
  77{
  78        return __va(address);
  79}
  80
  81/*
  82 * convert a physical pointer to a virtual kernel pointer for
  83 * /dev/mem access.
  84 */
  85#define xlate_dev_kmem_ptr(p)    __va(p)
  86#define xlate_dev_mem_ptr(p)    __va(p)
  87
  88/*
  89 * IO port access primitives.  Hexagon doesn't have special IO access
  90 * instructions; all I/O is memory mapped.
  91 *
  92 * in/out are used for "ports", but we don't have "port instructions",
  93 * so these are really just memory mapped too.
  94 */
  95
  96/*
  97 * readb - read byte from memory mapped device
  98 * @addr:  pointer to memory
  99 *
 100 * Operates on "I/O bus memory space"
 101 */
 102static inline u8 readb(const volatile void __iomem *addr)
 103{
 104        u8 val;
 105        asm volatile(
 106                "%0 = memb(%1);"
 107                : "=&r" (val)
 108                : "r" (addr)
 109        );
 110        return val;
 111}
 112
 113static inline u16 readw(const volatile void __iomem *addr)
 114{
 115        u16 val;
 116        asm volatile(
 117                "%0 = memh(%1);"
 118                : "=&r" (val)
 119                : "r" (addr)
 120        );
 121        return val;
 122}
 123
 124static inline u32 readl(const volatile void __iomem *addr)
 125{
 126        u32 val;
 127        asm volatile(
 128                "%0 = memw(%1);"
 129                : "=&r" (val)
 130                : "r" (addr)
 131        );
 132        return val;
 133}
 134
 135/*
 136 * writeb - write a byte to a memory location
 137 * @data: data to write to
 138 * @addr:  pointer to memory
 139 *
 140 */
 141static inline void writeb(u8 data, volatile void __iomem *addr)
 142{
 143        asm volatile(
 144                "memb(%0) = %1;"
 145                :
 146                : "r" (addr), "r" (data)
 147                : "memory"
 148        );
 149}
 150
 151static inline void writew(u16 data, volatile void __iomem *addr)
 152{
 153        asm volatile(
 154                "memh(%0) = %1;"
 155                :
 156                : "r" (addr), "r" (data)
 157                : "memory"
 158        );
 159
 160}
 161
 162static inline void writel(u32 data, volatile void __iomem *addr)
 163{
 164        asm volatile(
 165                "memw(%0) = %1;"
 166                :
 167                : "r" (addr), "r" (data)
 168                : "memory"
 169        );
 170}
 171
 172#define __raw_writeb writeb
 173#define __raw_writew writew
 174#define __raw_writel writel
 175
 176#define __raw_readb readb
 177#define __raw_readw readw
 178#define __raw_readl readl
 179
 180/*
 181 * http://comments.gmane.org/gmane.linux.ports.arm.kernel/117626
 182 */
 183
 184#define readb_relaxed __raw_readb
 185#define readw_relaxed __raw_readw
 186#define readl_relaxed __raw_readl
 187
 188#define writeb_relaxed __raw_writeb
 189#define writew_relaxed __raw_writew
 190#define writel_relaxed __raw_writel
 191
 192/*
 193 * Need an mtype somewhere in here, for cache type deals?
 194 * This is probably too long for an inline.
 195 */
 196void __iomem *ioremap_nocache(unsigned long phys_addr, unsigned long size);
 197
 198static inline void __iomem *ioremap(unsigned long phys_addr, unsigned long size)
 199{
 200        return ioremap_nocache(phys_addr, size);
 201}
 202
 203static inline void iounmap(volatile void __iomem *addr)
 204{
 205        __iounmap(addr);
 206}
 207
 208#define __raw_writel writel
 209
 210static inline void memcpy_fromio(void *dst, const volatile void __iomem *src,
 211        int count)
 212{
 213        memcpy(dst, (void *) src, count);
 214}
 215
 216static inline void memcpy_toio(volatile void __iomem *dst, const void *src,
 217        int count)
 218{
 219        memcpy((void *) dst, src, count);
 220}
 221
 222#define PCI_IO_ADDR     (volatile void __iomem *)
 223
 224/*
 225 * inb - read byte from I/O port or something
 226 * @port:  address in I/O space
 227 *
 228 * Operates on "I/O bus I/O space"
 229 */
 230static inline u8 inb(unsigned long port)
 231{
 232        return readb(_IO_BASE + (port & IO_SPACE_LIMIT));
 233}
 234
 235static inline u16 inw(unsigned long port)
 236{
 237        return readw(_IO_BASE + (port & IO_SPACE_LIMIT));
 238}
 239
 240static inline u32 inl(unsigned long port)
 241{
 242        return readl(_IO_BASE + (port & IO_SPACE_LIMIT));
 243}
 244
 245/*
 246 * outb - write a byte to a memory location
 247 * @data: data to write to
 248 * @addr:  address in I/O space
 249 */
 250static inline void outb(u8 data, unsigned long port)
 251{
 252        writeb(data, _IO_BASE + (port & IO_SPACE_LIMIT));
 253}
 254
 255static inline void outw(u16 data, unsigned long port)
 256{
 257        writew(data, _IO_BASE + (port & IO_SPACE_LIMIT));
 258}
 259
 260static inline void outl(u32 data, unsigned long port)
 261{
 262        writel(data, _IO_BASE + (port & IO_SPACE_LIMIT));
 263}
 264
 265#define outb_p outb
 266#define outw_p outw
 267#define outl_p outl
 268
 269#define inb_p inb
 270#define inw_p inw
 271#define inl_p inl
 272
 273static inline void insb(unsigned long port, void *buffer, int count)
 274{
 275        if (count) {
 276                u8 *buf = buffer;
 277                do {
 278                        u8 x = inb(port);
 279                        *buf++ = x;
 280                } while (--count);
 281        }
 282}
 283
 284static inline void insw(unsigned long port, void *buffer, int count)
 285{
 286        if (count) {
 287                u16 *buf = buffer;
 288                do {
 289                        u16 x = inw(port);
 290                        *buf++ = x;
 291                } while (--count);
 292        }
 293}
 294
 295static inline void insl(unsigned long port, void *buffer, int count)
 296{
 297        if (count) {
 298                u32 *buf = buffer;
 299                do {
 300                        u32 x = inw(port);
 301                        *buf++ = x;
 302                } while (--count);
 303        }
 304}
 305
 306static inline void outsb(unsigned long port, const void *buffer, int count)
 307{
 308        if (count) {
 309                const u8 *buf = buffer;
 310                do {
 311                        outb(*buf++, port);
 312                } while (--count);
 313        }
 314}
 315
 316static inline void outsw(unsigned long port, const void *buffer, int count)
 317{
 318        if (count) {
 319                const u16 *buf = buffer;
 320                do {
 321                        outw(*buf++, port);
 322                } while (--count);
 323        }
 324}
 325
 326static inline void outsl(unsigned long port, const void *buffer, int count)
 327{
 328        if (count) {
 329                const u32 *buf = buffer;
 330                do {
 331                        outl(*buf++, port);
 332                } while (--count);
 333        }
 334}
 335
 336#define flush_write_buffers() do { } while (0)
 337
 338#endif /* __KERNEL__ */
 339
 340#endif
 341