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
22 #ifndef _MEMIO_H
23 #define _MEMIO_H
24
25 #include "short_types.h"
26
27 #define IOBASE PCIL0_IOBASE
28
29 #define in_byte(from) read_byte( (uint8 *)(IOBASE | (from)))
30 #define in_word(from) read_word_little((uint16 *)(IOBASE | (from)))
31 #define in_long(from) read_long_little((uint32 *)(IOBASE | (from)))
32 #define out_byte(to, val) write_byte((uint8 *)(IOBASE | (to)), val)
33 #define out_word(to, val) write_word_little((uint16 *)(IOBASE | (to)), val)
34 #define out_long(to, val) write_long_little((uint32 *)(IOBASE | (to)), val)
35
read_byte(volatile uint8 * from)36 static inline uint8 read_byte(volatile uint8 *from)
37 {
38 int x;
39 asm volatile ("lbz %0,%1\n eieio\n sync" : "=r" (x) : "m" (*from));
40 return (uint8)x;
41 }
42
43
write_byte(volatile uint8 * to,uint8 x)44 static inline void write_byte(volatile uint8 *to, uint8 x)
45 {
46 asm volatile ("stb %1,%0\n eieio\n sync" : "=m" (*to) : "r" (x));
47 }
48
read_word_little(volatile uint16 * from)49 static inline uint16 read_word_little(volatile uint16 *from)
50 {
51 int x;
52 asm volatile ("lhbrx %0,0,%1\n eieio\n sync" : "=r" (x) : "r" (from), "m" (*from));
53 return (uint16)x;
54 }
55
read_word_big(volatile uint16 * from)56 static inline uint16 read_word_big(volatile uint16 *from)
57 {
58 int x;
59 asm volatile ("lhz %0,%1\n eieio\n sync" : "=r" (x) : "m" (*from));
60 return (uint16)x;
61 }
62
write_word_little(volatile uint16 * to,int x)63 static inline void write_word_little(volatile uint16 *to, int x)
64 {
65 asm volatile ("sthbrx %1,0,%2\n eieio\n sync" : "=m" (*to) : "r" (x), "r" (to));
66 }
67
write_word_big(volatile uint16 * to,int x)68 static inline void write_word_big(volatile uint16 *to, int x)
69 {
70 asm volatile ("sth %1,%0\n eieio\n sync" : "=m" (*to) : "r" (x));
71 }
72
read_long_little(volatile uint32 * from)73 static inline uint32 read_long_little(volatile uint32 *from)
74 {
75 unsigned long x;
76 asm volatile ("lwbrx %0,0,%1\n eieio\n sync" : "=r" (x) : "r" (from), "m"(*from));
77 return (uint32)x;
78 }
79
read_long_big(volatile uint32 * from)80 static inline uint32 read_long_big(volatile uint32 *from)
81 {
82 unsigned long x;
83 asm volatile ("lwz %0,%1\n eieio\n sync" : "=r" (x) : "m" (*from));
84 return (uint32)x;
85 }
86
write_long_little(volatile uint32 * to,uint32 x)87 static inline void write_long_little(volatile uint32 *to, uint32 x)
88 {
89 asm volatile ("stwbrx %1,0,%2\n eieio\n sync" : "=m" (*to) : "r" (x), "r" (to));
90 }
91
write_long_big(volatile uint32 * to,uint32 x)92 static inline void write_long_big(volatile uint32 *to, uint32 x)
93 {
94 asm volatile ("stw %1,%0\n eieio\n sync" : "=m" (*to) : "r" (x));
95 }
96
97 /*
98 #define CONFIG_ADDR(bus, devfn, offset) \
99 write_long_big((uint32 *)0xEEC00000, \
100 ((offset & 0xEC)<<24) | (devfn << 16) \
101 | (bus<<8) | 0x80);
102 #define CONFIG_DATA(offset,mask) ((void *)(0xEEC00004+(offset & mask)))
103
104 uint8 pci_read_cfg_byte(int32 bus, int32 devfn, int32 offset);
105 void pci_write_cfg_byte(int32 bus, int32 devfn, int32 offset, uint8 x);
106 uint16 pci_read_cfg_word(int32 bus, int32 devfn, int32 offset);
107 void pci_write_cfg_word(int32 bus, int32 devfn, int32 offset, uint16 x);
108 uint32 pci_read_cfg_long(int32 bus, int32 devfn, int32 offset);
109 void pci_write_cfg_long(int32 bus, int32 devfn, int32 offset, uint32 x);
110
111 #define POST_CODE(x) out_byte(0x80, (x))
112 */
113 #endif
114