commandProcessing.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* io.h: FRV I/O operations
  2. *
  3. * Copyright (C) 2004 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 License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * This gets interesting when talking to the PCI bus - the CPU is in big endian
  12. * mode, the PCI bus is little endian and the hardware in the middle can do
  13. * byte swapping
  14. */
  15. #ifndef _ASM_IO_H
  16. #define _ASM_IO_H
  17. #ifdef __KERNEL__
  18. #include <linux/types.h>
  19. #include <asm/virtconvert.h>
  20. #include <asm/string.h>
  21. #include <asm/mb-regs.h>
  22. #include <asm-generic/pci_iomap.h>
  23. #include <linux/delay.h>
  24. /*
  25. * swap functions are sometimes needed to interface little-endian hardware
  26. */
  27. static inline unsigned short _swapw(unsigned short v)
  28. {
  29. return ((v << 8) | (v >> 8));
  30. }
  31. static inline unsigned long _swapl(unsigned long v)
  32. {
  33. return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24));
  34. }
  35. //#define __iormb() asm volatile("membar")
  36. //#define __iowmb() asm volatile("membar")
  37. #define __raw_readb __builtin_read8
  38. #define __raw_readw __builtin_read16
  39. #define __raw_readl __builtin_read32
  40. #define __raw_writeb(datum, addr) __builtin_write8(addr, datum)
  41. #define __raw_writew(datum, addr) __builtin_write16(addr, datum)
  42. #define __raw_writel(datum, addr) __builtin_write32(addr, datum)
  43. static inline void io_outsb(unsigned int addr, const void *buf, int len)
  44. {
  45. unsigned long __ioaddr = (unsigned long) addr;
  46. const uint8_t *bp = buf;
  47. while (len--)
  48. __builtin_write8((volatile void __iomem *) __ioaddr, *bp++);
  49. }
  50. static inline void io_outsw(unsigned int addr, const void *buf, int len)
  51. {
  52. unsigned long __ioaddr = (unsigned long) addr;
  53. const uint16_t *bp = buf;
  54. while (len--)
  55. __builtin_write16((volatile void __iomem *) __ioaddr, (*bp++));
  56. }
  57. extern void __outsl_ns(unsigned int addr, const void *buf, int len);
  58. extern void __outsl_sw(unsigned int addr, const void *buf, int len);
  59. static inline void __outsl(unsigned int addr, const void *buf, int len, int swap)
  60. {
  61. unsigned long __ioaddr = (unsigned long) addr;
  62. if (!swap)
  63. __outsl_ns(__ioaddr, buf, len);
  64. else
  65. __outsl_sw(__ioaddr, buf, len);
  66. }
  67. static inline void io_insb(unsigned long addr, void *buf, int len)
  68. {
  69. uint8_t *bp = buf;
  70. while (len--)
  71. *bp++ = __builtin_read8((volatile void __iomem *) addr);
  72. }
  73. static inline void io_insw(unsigned long addr, void *buf, int len)
  74. {
  75. uint16_t *bp = buf;
  76. while (len--)
  77. *bp++ = __builtin_read16((volatile void __iomem *) addr);
  78. }