summaryrefslogtreecommitdiffstats
path: root/purgatory/arch/ia64/io.h
blob: 0f78580e3d53465168beb5cfe09d1228a8f55436 (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
#ifndef IO_H
#define IO_H
#define UNCACHED(x) (void *)((x)|(1UL<<63))
#define MF()	asm volatile ("mf.a" ::: "memory")
#define IO_SPACE_ENCODING(p)     ((((p) >> 2) << 12) | (p & 0xfff))
extern long __noio;
static inline void *io_addr (unsigned long port)
{
        unsigned long offset;
	unsigned long io_base;
	asm volatile ("mov %0=ar.k0":"=r"(io_base));
	offset = IO_SPACE_ENCODING(port);
        return UNCACHED(io_base | offset);
}

static inline unsigned int inb (unsigned long port)
{
        volatile unsigned char *addr = io_addr(port);
	unsigned char ret = 0;
	if (!__noio) {
		ret = *addr;
		MF();
	}
        return ret;
}

static inline unsigned int inw (unsigned long port)
{
        volatile unsigned short *addr = io_addr(port);
	unsigned short ret = 0;

	if (!__noio) {
		ret = *addr;
		MF();
	}
        return ret;
}

static inline unsigned int inl (unsigned long port)
{
	volatile unsigned int *addr = io_addr(port);
	unsigned int ret ;
	if (!__noio) {
		ret = *addr;
		MF();
	}
        return ret;
}

static inline void outb (unsigned char val, unsigned long port)
{
        volatile unsigned char *addr = io_addr(port);

	if (!__noio) {
		*addr = val;
		MF();
	}
}

static inline void outw (unsigned short val, unsigned long port)
{
        volatile unsigned short *addr = io_addr(port);

	if (!__noio) {
		*addr = val;
		MF();
	}
}

static inline void outl (unsigned int val, unsigned long port)
{
        volatile unsigned int *addr = io_addr(port);

	if (!__noio) {
		*addr = val;
		MF();
	}
}

static inline unsigned char readb(const volatile void  *addr)
{
	return __noio ? 0 :*(volatile unsigned char *) addr;
}
static inline unsigned short readw(const volatile void  *addr)
{
	return __noio ? 0 :*(volatile unsigned short *) addr;
}
static inline unsigned int readl(const volatile void  *addr)
{
	return __noio ? 0 :*(volatile unsigned int *) addr;
}

static inline void writeb(unsigned char b, volatile void  *addr)
{
	if (!__noio)
		*(volatile unsigned char *) addr = b;
}
static inline void writew(unsigned short b, volatile void  *addr)
{
	if (!__noio)
		*(volatile unsigned short *) addr = b;
}
static inline void writel(unsigned int b, volatile void  *addr)
{
	if (!__noio)
		*(volatile unsigned int *) addr = b;
}
#endif