Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / arch / x86 / core / x86_io.c
1 /*
2  * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19
20 FILE_LICENCE ( GPL2_OR_LATER );
21
22 #include <ipxe/io.h>
23 #include <ipxe/x86_io.h>
24
25 /** @file
26  *
27  * iPXE I/O API for x86
28  *
29  */
30
31 /**
32  * Read 64-bit qword from memory-mapped device
33  *
34  * @v io_addr           I/O address
35  * @ret data            Value read
36  *
37  * This routine uses MMX instructions.
38  */
39 static __unused uint64_t i386_readq ( volatile uint64_t *io_addr ) {
40         uint64_t data;
41         __asm__ __volatile__ ( "pushl %%edx\n\t"
42                                "pushl %%eax\n\t"
43                                "movq (%1), %%mm0\n\t"
44                                "movq %%mm0, (%%esp)\n\t"
45                                "popl %%eax\n\t"
46                                "popl %%edx\n\t"
47                                "emms\n\t"
48                                : "=A" ( data ) : "r" ( io_addr ) );
49         return data;
50 }
51
52 /**
53  * Write 64-bit qword to memory-mapped device
54  *
55  * @v data              Value to write
56  * @v io_addr           I/O address
57  *
58  * This routine uses MMX instructions.
59  */
60 static __unused void i386_writeq ( uint64_t data, volatile uint64_t *io_addr ) {
61         __asm__ __volatile__ ( "pushl %%edx\n\t"
62                                "pushl %%eax\n\t"
63                                "movq (%%esp), %%mm0\n\t"
64                                "movq %%mm0, (%1)\n\t"
65                                "popl %%eax\n\t"
66                                "popl %%edx\n\t"
67                                "emms\n\t"
68                                : : "A" ( data ), "r" ( io_addr ) );
69 }
70
71 PROVIDE_IOAPI_INLINE ( x86, phys_to_bus );
72 PROVIDE_IOAPI_INLINE ( x86, bus_to_phys );
73 PROVIDE_IOAPI_INLINE ( x86, ioremap );
74 PROVIDE_IOAPI_INLINE ( x86, iounmap );
75 PROVIDE_IOAPI_INLINE ( x86, io_to_bus );
76 PROVIDE_IOAPI_INLINE ( x86, readb );
77 PROVIDE_IOAPI_INLINE ( x86, readw );
78 PROVIDE_IOAPI_INLINE ( x86, readl );
79 PROVIDE_IOAPI_INLINE ( x86, writeb );
80 PROVIDE_IOAPI_INLINE ( x86, writew );
81 PROVIDE_IOAPI_INLINE ( x86, writel );
82 PROVIDE_IOAPI_INLINE ( x86, inb );
83 PROVIDE_IOAPI_INLINE ( x86, inw );
84 PROVIDE_IOAPI_INLINE ( x86, inl );
85 PROVIDE_IOAPI_INLINE ( x86, outb );
86 PROVIDE_IOAPI_INLINE ( x86, outw );
87 PROVIDE_IOAPI_INLINE ( x86, outl );
88 PROVIDE_IOAPI_INLINE ( x86, insb );
89 PROVIDE_IOAPI_INLINE ( x86, insw );
90 PROVIDE_IOAPI_INLINE ( x86, insl );
91 PROVIDE_IOAPI_INLINE ( x86, outsb );
92 PROVIDE_IOAPI_INLINE ( x86, outsw );
93 PROVIDE_IOAPI_INLINE ( x86, outsl );
94 PROVIDE_IOAPI_INLINE ( x86, iodelay );
95 PROVIDE_IOAPI_INLINE ( x86, mb );
96 #ifdef __x86_64__
97 PROVIDE_IOAPI_INLINE ( x86, readq );
98 PROVIDE_IOAPI_INLINE ( x86, writeq );
99 #else
100 PROVIDE_IOAPI ( x86, readq, i386_readq );
101 PROVIDE_IOAPI ( x86, writeq, i386_writeq );
102 #endif