summaryrefslogtreecommitdiffstats
path: root/arch/x86/include/asm/io.h
blob: f020510569b5dc94991fcf4245684ac4de9fa45b (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
/*
 * Mostly stolen from the linux kernel
 */

/**
 * @file
 * @brief x86 IO access functions
 */

#ifndef __ASM_X86_IO_H
#define __ASM_X86_IO_H

#include <asm/byteorder.h>

#define	IO_SPACE_LIMIT	0xffff

static inline void outb(unsigned char value, int port)
{
	asm volatile("outb %b0, %w1" : : "a"(value), "Nd"(port));
}

static inline void outw(unsigned short value, int port)
{
	asm volatile("outw %w0, %w1" : : "a"(value), "Nd"(port));
}

static inline void outl(unsigned long value, int port)
{
	asm volatile("outl %0, %w1" : : "a"(value), "Nd"(port));
}

static inline unsigned char inb(int port)
{
	unsigned char value;
	asm volatile("inb %w1, %b0" : "=a"(value) : "Nd"(port));
	return value;
}

static inline unsigned short inw(int port)
{
	unsigned short value;
	asm volatile("inw %w1, %w0" : "=a"(value) : "Nd"(port));
	return value;
}

static inline unsigned long inl(int port)
{
	unsigned long value;
	asm volatile("inl %w1, %0" : "=a"(value) : "Nd"(port));
	return value;
}

#define build_mmio_read(name, size, type, reg, barrier) \
 static inline type name(const volatile void *addr) \
 { type ret; asm volatile("mov" size " %1,%0":reg (ret) \
 :"m" (*(volatile type*)addr) barrier); return ret; }

build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
build_mmio_read(readl, "l", unsigned int, "=r", :"memory")

#define build_mmio_write(name, size, type, reg, barrier) \
 static inline void name(type val, volatile void *addr) \
 { asm volatile("mov" size " %0,%1": :reg (val), \
 "m" (*(volatile type*)addr) barrier); }

build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
build_mmio_write(writew, "w", unsigned short, "r", :"memory")
build_mmio_write(writel, "l", unsigned int, "r", :"memory")

/* do a tiny io delay */
static inline void io_delay(void)
{
	inb(0x80);
}

#endif	/* __ASM_X86_IO_H */