wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Memory mapped IO |
| 3 | * |
| 4 | * (C) Copyright 2002 |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 5 | * Hyperion Entertainment, ThomasF@hyperion-entertainment.com |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 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 |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 19 | * |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 20 | */ |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 21 | |
| 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 | |
| 37 | static 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 | |
| 45 | static 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 | |
| 50 | static 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 | |
| 57 | static 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 | |
| 64 | static 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 | |
| 69 | static 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 | |
| 74 | static 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 | |
| 81 | static 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 | |
| 88 | static 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 | |
| 93 | static 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, \ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 100 | ((offset & 0xFC)<<24) | (devfn << 16) \ |
| 101 | | (bus<<8) | 0x80); |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 102 | #define CONFIG_DATA(offset,mask) ((void *)(0xFEE00CFC+(offset & mask))) |
| 103 | |
| 104 | |
| 105 | uint8 pci_read_cfg_byte(int32 bus, int32 devfn, int32 offset); |
| 106 | void pci_write_cfg_byte(int32 bus, int32 devfn, int32 offset, uint8 x); |
| 107 | uint16 pci_read_cfg_word(int32 bus, int32 devfn, int32 offset); |
| 108 | void pci_write_cfg_word(int32 bus, int32 devfn, int32 offset, uint16 x); |
| 109 | uint32 pci_read_cfg_long(int32 bus, int32 devfn, int32 offset); |
| 110 | void pci_write_cfg_long(int32 bus, int32 devfn, int32 offset, uint32 x); |
| 111 | |
| 112 | |
| 113 | #endif |