summaryrefslogtreecommitdiff
path: root/board/MAI/AmigaOneG3SE/memio.h
blob: df0839f91dc03ec6e9eb88aa4af97aed22bc688f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Memory mapped IO
 *
 * (C) Copyright 2002
 * Hyperion Entertainment, ThomasF@hyperion-entertainment.com 
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 * You may also use this under a BSD license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	
 *
 */ 

#ifndef _MEMIO_H
#define _MEMIO_H

#include "short_types.h"

#define IOBASE 0xFE000000

#define in_byte(from) read_byte( (uint8 *)(IOBASE | (from)))
#define in_word(from) read_word_little((uint16 *)(IOBASE | (from)))
#define in_long(from) read_long_little((uint32 *)(IOBASE | (from)))
#define out_byte(to, val) write_byte((uint8 *)(IOBASE | (to)), val)
#define out_word(to, val) write_word_little((uint16 *)(IOBASE | (to)), val)
#define out_long(to, val) write_long_little((uint32 *)(IOBASE | (to)), val)


static inline uint8 read_byte(volatile uint8 *from)
{
    int x;
    asm volatile ("lbz %0,%1\n eieio\n sync" : "=r" (x) : "m" (*from));
    return (uint8)x;
}


static inline void write_byte(volatile uint8 *to, uint8 x)
{
    asm volatile ("stb %1,%0\n eieio\n sync" : "=m" (*to) : "r" (x));
}

static inline uint16 read_word_little(volatile uint16 *from)
{
    int x;
    asm volatile ("lhbrx %0,0,%1\n eieio\n sync" : "=r" (x) : "r" (from), "m" (*from));
    return (uint16)x;
}

static inline uint16 read_word_big(volatile uint16 *from)
{
    int x;
    asm volatile ("lhz %0,%1\n eieio\n sync" : "=r" (x) : "m" (*from));
    return (uint16)x;
}

static inline void write_word_little(volatile uint16 *to, int x)
{
    asm volatile ("sthbrx %1,0,%2\n eieio\n sync" : "=m" (*to) : "r" (x), "r" (to));
}

static inline void write_word_big(volatile uint16 *to, int x)
{
    asm volatile ("sth %1,%0\n eieio\n sync" : "=m" (*to) : "r" (x));
}

static inline uint32 read_long_little(volatile uint32 *from)
{
    unsigned long x;
    asm volatile ("lwbrx %0,0,%1\n eieio\n sync" : "=r" (x) : "r" (from), "m"(*from));
    return (uint32)x;
}

static inline uint32 read_long_big(volatile uint32 *from)
{
    unsigned long x;
    asm volatile ("lwz %0,%1\n eieio\n sync" : "=r" (x) : "m" (*from));
    return (uint32)x;
}

static inline void write_long_little(volatile uint32 *to, uint32 x)
{
    asm volatile ("stwbrx %1,0,%2\n eieio\n sync" : "=m" (*to) : "r" (x), "r" (to));
}

static inline void write_long_big(volatile uint32 *to, uint32 x)
{
    asm volatile ("stw %1,%0\n eieio\n sync" : "=m" (*to) : "r" (x));
}

#define CONFIG_ADDR(bus, devfn, offset) \
    write_long_big((uint32 *)0xFEC00CF8,           \
                   ((offset & 0xFC)<<24) | (devfn << 16)  \
                   | (bus<<8) | 0x80);
#define CONFIG_DATA(offset,mask) ((void *)(0xFEE00CFC+(offset & mask)))


uint8 pci_read_cfg_byte(int32 bus, int32 devfn, int32 offset);
void pci_write_cfg_byte(int32 bus, int32 devfn, int32 offset, uint8 x);
uint16 pci_read_cfg_word(int32 bus, int32 devfn, int32 offset);
void pci_write_cfg_word(int32 bus, int32 devfn, int32 offset, uint16 x);
uint32 pci_read_cfg_long(int32 bus, int32 devfn, int32 offset);
void pci_write_cfg_long(int32 bus, int32 devfn, int32 offset, uint32 x);


#endif