memio.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Memory mapped IO
  3. *
  4. * (C) Copyright 2002
  5. * Hyperion Entertainment, ThomasF@hyperion-entertainment.com
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. * You may also use this under a BSD license.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. *
  20. */
  21. #ifndef _MEMIO_H
  22. #define _MEMIO_H
  23. #include "short_types.h"
  24. #define IOBASE 0xFE000000
  25. #define in_byte(from) read_byte( (uint8 *)(IOBASE | (from)))
  26. #define in_word(from) read_word_little((uint16 *)(IOBASE | (from)))
  27. #define in_long(from) read_long_little((uint32 *)(IOBASE | (from)))
  28. #define out_byte(to, val) write_byte((uint8 *)(IOBASE | (to)), val)
  29. #define out_word(to, val) write_word_little((uint16 *)(IOBASE | (to)), val)
  30. #define out_long(to, val) write_long_little((uint32 *)(IOBASE | (to)), val)
  31. static inline uint8 read_byte(volatile uint8 *from)
  32. {
  33. int x;
  34. asm volatile ("lbz %0,%1\n eieio\n sync" : "=r" (x) : "m" (*from));
  35. return (uint8)x;
  36. }
  37. static inline void write_byte(volatile uint8 *to, uint8 x)
  38. {
  39. asm volatile ("stb %1,%0\n eieio\n sync" : "=m" (*to) : "r" (x));
  40. }
  41. static inline uint16 read_word_little(volatile uint16 *from)
  42. {
  43. int x;
  44. asm volatile ("lhbrx %0,0,%1\n eieio\n sync" : "=r" (x) : "r" (from), "m" (*from));
  45. return (uint16)x;
  46. }
  47. static inline uint16 read_word_big(volatile uint16 *from)
  48. {
  49. int x;
  50. asm volatile ("lhz %0,%1\n eieio\n sync" : "=r" (x) : "m" (*from));
  51. return (uint16)x;
  52. }
  53. static inline void write_word_little(volatile uint16 *to, int x)
  54. {
  55. asm volatile ("sthbrx %1,0,%2\n eieio\n sync" : "=m" (*to) : "r" (x), "r" (to));
  56. }
  57. static inline void write_word_big(volatile uint16 *to, int x)
  58. {
  59. asm volatile ("sth %1,%0\n eieio\n sync" : "=m" (*to) : "r" (x));
  60. }
  61. static inline uint32 read_long_little(volatile uint32 *from)
  62. {
  63. unsigned long x;
  64. asm volatile ("lwbrx %0,0,%1\n eieio\n sync" : "=r" (x) : "r" (from), "m"(*from));
  65. return (uint32)x;
  66. }
  67. static inline uint32 read_long_big(volatile uint32 *from)
  68. {
  69. unsigned long x;
  70. asm volatile ("lwz %0,%1\n eieio\n sync" : "=r" (x) : "m" (*from));
  71. return (uint32)x;
  72. }
  73. static inline void write_long_little(volatile uint32 *to, uint32 x)
  74. {
  75. asm volatile ("stwbrx %1,0,%2\n eieio\n sync" : "=m" (*to) : "r" (x), "r" (to));
  76. }
  77. static inline void write_long_big(volatile uint32 *to, uint32 x)
  78. {
  79. asm volatile ("stw %1,%0\n eieio\n sync" : "=m" (*to) : "r" (x));
  80. }
  81. #define CONFIG_ADDR(bus, devfn, offset) \
  82. write_long_big((uint32 *)0xFEC00CF8, \
  83. ((offset & 0xFC)<<24) | (devfn << 16) \
  84. | (bus<<8) | 0x80);
  85. #define CONFIG_DATA(offset,mask) ((void *)(0xFEE00CFC+(offset & mask)))
  86. uint8 pci_read_cfg_byte(int32 bus, int32 devfn, int32 offset);
  87. void pci_write_cfg_byte(int32 bus, int32 devfn, int32 offset, uint8 x);
  88. uint16 pci_read_cfg_word(int32 bus, int32 devfn, int32 offset);
  89. void pci_write_cfg_word(int32 bus, int32 devfn, int32 offset, uint16 x);
  90. uint32 pci_read_cfg_long(int32 bus, int32 devfn, int32 offset);
  91. void pci_write_cfg_long(int32 bus, int32 devfn, int32 offset, uint32 x);
  92. #endif