iPXE
x86_io.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #include <ipxe/io.h>
00027 #include <ipxe/x86_io.h>
00028 
00029 /** @file
00030  *
00031  * iPXE I/O API for x86
00032  *
00033  */
00034 
00035 /**
00036  * Read 64-bit qword from memory-mapped device
00037  *
00038  * @v io_addr           I/O address
00039  * @ret data            Value read
00040  *
00041  * This routine uses MMX instructions.
00042  */
00043 static __unused uint64_t i386_readq ( volatile uint64_t *io_addr ) {
00044         uint64_t data;
00045         __asm__ __volatile__ ( "pushl %%edx\n\t"
00046                                "pushl %%eax\n\t"
00047                                "movq (%1), %%mm0\n\t"
00048                                "movq %%mm0, (%%esp)\n\t"
00049                                "popl %%eax\n\t"
00050                                "popl %%edx\n\t"
00051                                "emms\n\t"
00052                                : "=A" ( data ) : "r" ( io_addr ) );
00053         return data;
00054 }
00055 
00056 /**
00057  * Write 64-bit qword to memory-mapped device
00058  *
00059  * @v data              Value to write
00060  * @v io_addr           I/O address
00061  *
00062  * This routine uses MMX instructions.
00063  */
00064 static __unused void i386_writeq ( uint64_t data, volatile uint64_t *io_addr ) {
00065         __asm__ __volatile__ ( "pushl %%edx\n\t"
00066                                "pushl %%eax\n\t"
00067                                "movq (%%esp), %%mm0\n\t"
00068                                "movq %%mm0, (%1)\n\t"
00069                                "popl %%eax\n\t"
00070                                "popl %%edx\n\t"
00071                                "emms\n\t"
00072                                : : "A" ( data ), "r" ( io_addr ) );
00073 }
00074 
00075 PROVIDE_IOAPI_INLINE ( x86, phys_to_bus );
00076 PROVIDE_IOAPI_INLINE ( x86, bus_to_phys );
00077 PROVIDE_IOAPI_INLINE ( x86, readb );
00078 PROVIDE_IOAPI_INLINE ( x86, readw );
00079 PROVIDE_IOAPI_INLINE ( x86, readl );
00080 PROVIDE_IOAPI_INLINE ( x86, writeb );
00081 PROVIDE_IOAPI_INLINE ( x86, writew );
00082 PROVIDE_IOAPI_INLINE ( x86, writel );
00083 PROVIDE_IOAPI_INLINE ( x86, inb );
00084 PROVIDE_IOAPI_INLINE ( x86, inw );
00085 PROVIDE_IOAPI_INLINE ( x86, inl );
00086 PROVIDE_IOAPI_INLINE ( x86, outb );
00087 PROVIDE_IOAPI_INLINE ( x86, outw );
00088 PROVIDE_IOAPI_INLINE ( x86, outl );
00089 PROVIDE_IOAPI_INLINE ( x86, insb );
00090 PROVIDE_IOAPI_INLINE ( x86, insw );
00091 PROVIDE_IOAPI_INLINE ( x86, insl );
00092 PROVIDE_IOAPI_INLINE ( x86, outsb );
00093 PROVIDE_IOAPI_INLINE ( x86, outsw );
00094 PROVIDE_IOAPI_INLINE ( x86, outsl );
00095 PROVIDE_IOAPI_INLINE ( x86, iodelay );
00096 PROVIDE_IOAPI_INLINE ( x86, mb );
00097 #ifdef __x86_64__
00098 PROVIDE_IOAPI_INLINE ( x86, readq );
00099 PROVIDE_IOAPI_INLINE ( x86, writeq );
00100 #else
00101 PROVIDE_IOAPI ( x86, readq, i386_readq );
00102 PROVIDE_IOAPI ( x86, writeq, i386_writeq );
00103 #endif