These changes are the raw update to qemu-2.6.
[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  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26 #include <ipxe/io.h>
27 #include <ipxe/x86_io.h>
28
29 /** @file
30  *
31  * iPXE I/O API for x86
32  *
33  */
34
35 /**
36  * Read 64-bit qword from memory-mapped device
37  *
38  * @v io_addr           I/O address
39  * @ret data            Value read
40  *
41  * This routine uses MMX instructions.
42  */
43 static __unused uint64_t i386_readq ( volatile uint64_t *io_addr ) {
44         uint64_t data;
45         __asm__ __volatile__ ( "pushl %%edx\n\t"
46                                "pushl %%eax\n\t"
47                                "movq (%1), %%mm0\n\t"
48                                "movq %%mm0, (%%esp)\n\t"
49                                "popl %%eax\n\t"
50                                "popl %%edx\n\t"
51                                "emms\n\t"
52                                : "=A" ( data ) : "r" ( io_addr ) );
53         return data;
54 }
55
56 /**
57  * Write 64-bit qword to memory-mapped device
58  *
59  * @v data              Value to write
60  * @v io_addr           I/O address
61  *
62  * This routine uses MMX instructions.
63  */
64 static __unused void i386_writeq ( uint64_t data, volatile uint64_t *io_addr ) {
65         __asm__ __volatile__ ( "pushl %%edx\n\t"
66                                "pushl %%eax\n\t"
67                                "movq (%%esp), %%mm0\n\t"
68                                "movq %%mm0, (%1)\n\t"
69                                "popl %%eax\n\t"
70                                "popl %%edx\n\t"
71                                "emms\n\t"
72                                : : "A" ( data ), "r" ( io_addr ) );
73 }
74
75 PROVIDE_IOAPI_INLINE ( x86, phys_to_bus );
76 PROVIDE_IOAPI_INLINE ( x86, bus_to_phys );
77 PROVIDE_IOAPI_INLINE ( x86, ioremap );
78 PROVIDE_IOAPI_INLINE ( x86, iounmap );
79 PROVIDE_IOAPI_INLINE ( x86, io_to_bus );
80 PROVIDE_IOAPI_INLINE ( x86, readb );
81 PROVIDE_IOAPI_INLINE ( x86, readw );
82 PROVIDE_IOAPI_INLINE ( x86, readl );
83 PROVIDE_IOAPI_INLINE ( x86, writeb );
84 PROVIDE_IOAPI_INLINE ( x86, writew );
85 PROVIDE_IOAPI_INLINE ( x86, writel );
86 PROVIDE_IOAPI_INLINE ( x86, inb );
87 PROVIDE_IOAPI_INLINE ( x86, inw );
88 PROVIDE_IOAPI_INLINE ( x86, inl );
89 PROVIDE_IOAPI_INLINE ( x86, outb );
90 PROVIDE_IOAPI_INLINE ( x86, outw );
91 PROVIDE_IOAPI_INLINE ( x86, outl );
92 PROVIDE_IOAPI_INLINE ( x86, insb );
93 PROVIDE_IOAPI_INLINE ( x86, insw );
94 PROVIDE_IOAPI_INLINE ( x86, insl );
95 PROVIDE_IOAPI_INLINE ( x86, outsb );
96 PROVIDE_IOAPI_INLINE ( x86, outsw );
97 PROVIDE_IOAPI_INLINE ( x86, outsl );
98 PROVIDE_IOAPI_INLINE ( x86, iodelay );
99 PROVIDE_IOAPI_INLINE ( x86, mb );
100 #ifdef __x86_64__
101 PROVIDE_IOAPI_INLINE ( x86, readq );
102 PROVIDE_IOAPI_INLINE ( x86, writeq );
103 #else
104 PROVIDE_IOAPI ( x86, readq, i386_readq );
105 PROVIDE_IOAPI ( x86, writeq, i386_writeq );
106 #endif