iPXE
x86_io.c
Go to the documentation of this file.
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 
83 PROVIDE_IOAPI_INLINE ( x86, inb );
84 PROVIDE_IOAPI_INLINE ( x86, inw );
85 PROVIDE_IOAPI_INLINE ( x86, inl );
86 PROVIDE_IOAPI_INLINE ( x86, outb );
87 PROVIDE_IOAPI_INLINE ( x86, outw );
88 PROVIDE_IOAPI_INLINE ( x86, outl );
89 PROVIDE_IOAPI_INLINE ( x86, insb );
90 PROVIDE_IOAPI_INLINE ( x86, insw );
91 PROVIDE_IOAPI_INLINE ( x86, insl );
96 PROVIDE_IOAPI_INLINE ( x86, mb );
97 #ifdef __x86_64__
100 #else
101 PROVIDE_IOAPI ( x86, readq, i386_readq );
103 #endif
iPXE I/O API
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
uint16_t inw(volatile uint16_t *io_addr)
Read 16-bit word from I/O-mapped device.
#define outw(data, io_addr)
Definition: io.h:319
uint64_t readq(volatile uint64_t *io_addr)
Read 64-bit qword from memory-mapped device.
uint16_t readw(volatile uint16_t *io_addr)
Read 16-bit word from memory-mapped device.
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
void outsw(volatile uint16_t *io_addr, const uint16_t *data, unsigned int count)
Write 16-bit words to I/O-mapped device.
unsigned long long uint64_t
Definition: stdint.h:13
void insb(volatile uint8_t *io_addr, uint8_t *data, unsigned int count)
Read bytes from I/O-mapped device.
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
PROVIDE_IOAPI_INLINE(x86, phys_to_bus)
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static __unused void i386_writeq(uint64_t data, volatile uint64_t *io_addr)
Write 64-bit qword to memory-mapped device.
Definition: x86_io.c:64
iPXE I/O API for x86
void insl(volatile uint32_t *io_addr, uint32_t *data, unsigned int count)
Read 32-bit words from I/O-mapped device.
#define outl(data, io_addr)
Definition: io.h:329
void insw(volatile uint16_t *io_addr, uint16_t *data, unsigned int count)
Read 16-bit words from I/O-mapped device.
uint8_t inb(volatile uint8_t *io_addr)
Read byte from I/O-mapped device.
unsigned long phys_to_bus(unsigned long phys_addr)
Convert physical address to a bus address.
__asm__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
void outsb(volatile uint8_t *io_addr, const uint8_t *data, unsigned int count)
Write bytes to I/O-mapped device.
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
#define outb(data, io_addr)
Definition: io.h:309
#define writew
Definition: w89c840.c:159
uint32_t inl(volatile uint32_t *io_addr)
Read 32-bit dword from I/O-mapped device.
static __unused uint64_t i386_readq(volatile uint64_t *io_addr)
Read 64-bit qword from memory-mapped device.
Definition: x86_io.c:43
void outsl(volatile uint32_t *io_addr, const uint32_t *data, unsigned int count)
Write 32-bit words to I/O-mapped device.
void mb(void)
Memory barrier.
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
void iodelay(void)
Slow down I/O.
unsigned long bus_to_phys(unsigned long bus_addr)
Convert bus address to a physical address.
void writeq(uint64_t data, volatile uint64_t *io_addr)
Write 64-bit qword to memory-mapped device.
PROVIDE_IOAPI(x86, readq, i386_readq)