blob: f5ce303070b0c7ec32f4a6569c07f4debee1171e [file] [log] [blame]
wdenkc7de8292002-11-19 11:04:11 +00001/*
2 * Memory mapped IO
3 *
4 * (C) Copyright 2002
wdenk8bde7f72003-06-27 21:31:46 +00005 * Hyperion Entertainment, ThomasF@hyperion-entertainment.com
wdenkc7de8292002-11-19 11:04:11 +00006 *
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
wdenk8bde7f72003-06-27 21:31:46 +000018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
wdenkc7de8292002-11-19 11:04:11 +000019 *
wdenk8bde7f72003-06-27 21:31:46 +000020 */
wdenkc7de8292002-11-19 11:04:11 +000021
22#ifndef _MEMIO_H
23#define _MEMIO_H
24
25#include "short_types.h"
26
27#define IOBASE 0xFE000000
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
36
37static inline uint8 read_byte(volatile uint8 *from)
38{
39 int x;
40 asm volatile ("lbz %0,%1\n eieio\n sync" : "=r" (x) : "m" (*from));
41 return (uint8)x;
42}
43
44
45static inline void write_byte(volatile uint8 *to, uint8 x)
46{
47 asm volatile ("stb %1,%0\n eieio\n sync" : "=m" (*to) : "r" (x));
48}
49
50static inline uint16 read_word_little(volatile uint16 *from)
51{
52 int x;
53 asm volatile ("lhbrx %0,0,%1\n eieio\n sync" : "=r" (x) : "r" (from), "m" (*from));
54 return (uint16)x;
55}
56
57static inline uint16 read_word_big(volatile uint16 *from)
58{
59 int x;
60 asm volatile ("lhz %0,%1\n eieio\n sync" : "=r" (x) : "m" (*from));
61 return (uint16)x;
62}
63
64static inline void write_word_little(volatile uint16 *to, int x)
65{
66 asm volatile ("sthbrx %1,0,%2\n eieio\n sync" : "=m" (*to) : "r" (x), "r" (to));
67}
68
69static inline void write_word_big(volatile uint16 *to, int x)
70{
71 asm volatile ("sth %1,%0\n eieio\n sync" : "=m" (*to) : "r" (x));
72}
73
74static inline uint32 read_long_little(volatile uint32 *from)
75{
76 unsigned long x;
77 asm volatile ("lwbrx %0,0,%1\n eieio\n sync" : "=r" (x) : "r" (from), "m"(*from));
78 return (uint32)x;
79}
80
81static inline uint32 read_long_big(volatile uint32 *from)
82{
83 unsigned long x;
84 asm volatile ("lwz %0,%1\n eieio\n sync" : "=r" (x) : "m" (*from));
85 return (uint32)x;
86}
87
88static inline void write_long_little(volatile uint32 *to, uint32 x)
89{
90 asm volatile ("stwbrx %1,0,%2\n eieio\n sync" : "=m" (*to) : "r" (x), "r" (to));
91}
92
93static inline void write_long_big(volatile uint32 *to, uint32 x)
94{
95 asm volatile ("stw %1,%0\n eieio\n sync" : "=m" (*to) : "r" (x));
96}
97
98#define CONFIG_ADDR(bus, devfn, offset) \
99 write_long_big((uint32 *)0xFEC00CF8, \
wdenk8bde7f72003-06-27 21:31:46 +0000100 ((offset & 0xFC)<<24) | (devfn << 16) \
101 | (bus<<8) | 0x80);
wdenkc7de8292002-11-19 11:04:11 +0000102#define CONFIG_DATA(offset,mask) ((void *)(0xFEE00CFC+(offset & mask)))
103
104
105uint8 pci_read_cfg_byte(int32 bus, int32 devfn, int32 offset);
106void pci_write_cfg_byte(int32 bus, int32 devfn, int32 offset, uint8 x);
107uint16 pci_read_cfg_word(int32 bus, int32 devfn, int32 offset);
108void pci_write_cfg_word(int32 bus, int32 devfn, int32 offset, uint16 x);
109uint32 pci_read_cfg_long(int32 bus, int32 devfn, int32 offset);
110void pci_write_cfg_long(int32 bus, int32 devfn, int32 offset, uint32 x);
111
112
113#endif