iPXE
x86_io.c File Reference

iPXE I/O API for x86 More...

#include <ipxe/io.h>
#include <ipxe/x86_io.h>

Go to the source code of this file.

Macros

#define PIO_THRESHOLD   0x10000
 Threshold for port I/O-mapped addresses.
#define X86_IOREADX(_api_func, _suffix, _type)
 Read from I/O-mapped or memory-mapped device.
#define X86_IOWRITEX(_api_func, _suffix, _type)
 Write to I/O-mapped or memory-mapped device.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 X86_IOREADX (ioread8, b, uint8_t)
 X86_IOREADX (ioread16, w, uint16_t)
 X86_IOREADX (ioread32, l, uint32_t)
 X86_IOWRITEX (iowrite8, b, uint8_t)
 X86_IOWRITEX (iowrite16, w, uint16_t)
 X86_IOWRITEX (iowrite32, l, uint32_t)
static __unused uint64_t i386_readq (volatile uint64_t *io_addr)
 Read 64-bit qword from memory-mapped device.
static __unused void i386_writeq (uint64_t data, volatile uint64_t *io_addr)
 Write 64-bit qword to memory-mapped device.
 PROVIDE_IOAPI_INLINE (x86, phys_to_bus)
 PROVIDE_IOAPI_INLINE (x86, bus_to_phys)
 PROVIDE_IOAPI_INLINE (x86, readb)
 PROVIDE_IOAPI_INLINE (x86, readw)
 PROVIDE_IOAPI_INLINE (x86, readl)
 PROVIDE_IOAPI_INLINE (x86, writeb)
 PROVIDE_IOAPI_INLINE (x86, writew)
 PROVIDE_IOAPI_INLINE (x86, writel)
 PROVIDE_IOAPI_INLINE (x86, inb)
 PROVIDE_IOAPI_INLINE (x86, inw)
 PROVIDE_IOAPI_INLINE (x86, inl)
 PROVIDE_IOAPI_INLINE (x86, outb)
 PROVIDE_IOAPI_INLINE (x86, outw)
 PROVIDE_IOAPI_INLINE (x86, outl)
 PROVIDE_IOAPI_INLINE (x86, insb)
 PROVIDE_IOAPI_INLINE (x86, insw)
 PROVIDE_IOAPI_INLINE (x86, insl)
 PROVIDE_IOAPI_INLINE (x86, outsb)
 PROVIDE_IOAPI_INLINE (x86, outsw)
 PROVIDE_IOAPI_INLINE (x86, outsl)
 PROVIDE_IOAPI_INLINE (x86, iodelay)
 PROVIDE_IOAPI_INLINE (x86, mb)
 PROVIDE_IOAPI (x86, readq, i386_readq)
 PROVIDE_IOAPI (x86, writeq, i386_writeq)
 PROVIDE_IOAPI (x86, ioread8, x86_ioread8)
 PROVIDE_IOAPI (x86, ioread16, x86_ioread16)
 PROVIDE_IOAPI (x86, ioread32, x86_ioread32)
 PROVIDE_IOAPI (x86, iowrite8, x86_iowrite8)
 PROVIDE_IOAPI (x86, iowrite16, x86_iowrite16)
 PROVIDE_IOAPI (x86, iowrite32, x86_iowrite32)

Detailed Description

iPXE I/O API for x86

Definition in file x86_io.c.

Macro Definition Documentation

◆ PIO_THRESHOLD

#define PIO_THRESHOLD   0x10000

Threshold for port I/O-mapped addresses.

On x86, port I/O instructions (inb/outb/etc) can take only an 8-bit or 16-bit address (in dx). All I/O ports must therefore have a value in the first 64kB of the address space.

Virtual addresses below 64kB can never be MMIO addresses:

  • In the UEFI memory model and x86_64 BIOS memory model, virtual addresses below 64kB are identity-mapped to the corresponding physical address. Since the first 64kB of address space is always RAM, no MMIO device can exist within this region.
  • In the i386 BIOS memory model, virtual addresses below 64kB cover the iPXE binary itself (which starts at address zero). Since the size of .textdata can never realistically be below 64kB (not least since the heap alone is 512kB), and since iPXE is placed into RAM as a contiguous block, no MMIO device can exist within this region.

We therefore know that any (virtual) address returned by ioremap() must be outside the first 64kB of the address space. We can therefore use this as a threshold to determine whether a given address is a port I/O address or an MMIO address.

Definition at line 60 of file x86_io.c.

◆ X86_IOREADX

#define X86_IOREADX ( _api_func,
_suffix,
_type )
Value:
static _type x86_ ## _api_func ( volatile _type *io_addr ) { \
if ( ( ( intptr_t ) io_addr ) < PIO_THRESHOLD ) { \
return in ## _suffix ( io_addr ); \
} else { \
return read ## _suffix ( io_addr ); \
} \
}
__be32 in[4]
Definition CIB_PRM.h:7
unsigned long intptr_t
Definition stdint.h:21
struct option_descriptor read[1]
Definition nvo_cmd.c:116
#define PIO_THRESHOLD
Threshold for port I/O-mapped addresses.
Definition x86_io.c:60

Read from I/O-mapped or memory-mapped device.

Parameters
io_addrI/O address
Return values
dataValue read

Definition at line 68 of file x86_io.c.

68#define X86_IOREADX( _api_func, _suffix, _type ) \
69static _type x86_ ## _api_func ( volatile _type *io_addr ) { \
70 if ( ( ( intptr_t ) io_addr ) < PIO_THRESHOLD ) { \
71 return in ## _suffix ( io_addr ); \
72 } else { \
73 return read ## _suffix ( io_addr ); \
74 } \
75}

◆ X86_IOWRITEX

#define X86_IOWRITEX ( _api_func,
_suffix,
_type )
Value:
static void x86_ ## _api_func ( _type data, volatile _type *io_addr ) { \
if ( ( ( intptr_t ) io_addr ) < PIO_THRESHOLD ) { \
out ## _suffix ( data, io_addr ); \
} else { \
write ## _suffix ( data, io_addr ); \
} \
}
__be32 out[4]
Definition CIB_PRM.h:8
uint8_t data[48]
Additional event data.
Definition ena.h:11
device nvs write
Definition threewire.h:62

Write to I/O-mapped or memory-mapped device.

Parameters
dataValue to write
io_addrI/O address

Definition at line 86 of file x86_io.c.

86#define X86_IOWRITEX( _api_func, _suffix, _type ) \
87static void x86_ ## _api_func ( _type data, volatile _type *io_addr ) { \
88 if ( ( ( intptr_t ) io_addr ) < PIO_THRESHOLD ) { \
89 out ## _suffix ( data, io_addr ); \
90 } else { \
91 write ## _suffix ( data, io_addr ); \
92 } \
93}

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ X86_IOREADX() [1/3]

X86_IOREADX ( ioread8 ,
b ,
uint8_t  )

References ioread8.

◆ X86_IOREADX() [2/3]

X86_IOREADX ( ioread16 ,
w ,
uint16_t  )

References ioread16.

◆ X86_IOREADX() [3/3]

X86_IOREADX ( ioread32 ,
l ,
uint32_t  )

References ioread32, and l.

◆ X86_IOWRITEX() [1/3]

X86_IOWRITEX ( iowrite8 ,
b ,
uint8_t  )

References iowrite8.

◆ X86_IOWRITEX() [2/3]

X86_IOWRITEX ( iowrite16 ,
w ,
uint16_t  )

References iowrite16.

◆ X86_IOWRITEX() [3/3]

X86_IOWRITEX ( iowrite32 ,
l ,
uint32_t  )

References iowrite32, and l.

◆ i386_readq()

__unused uint64_t i386_readq ( volatile uint64_t * io_addr)
static

Read 64-bit qword from memory-mapped device.

Parameters
io_addrI/O address
Return values
dataValue read

This routine uses MMX instructions.

Definition at line 106 of file x86_io.c.

106 {
108 __asm__ __volatile__ ( "pushl %%edx\n\t"
109 "pushl %%eax\n\t"
110 "movq (%1), %%mm0\n\t"
111 "movq %%mm0, (%%esp)\n\t"
112 "popl %%eax\n\t"
113 "popl %%edx\n\t"
114 "emms\n\t"
115 : "=A" ( data ) : "r" ( io_addr ) );
116 return data;
117}
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
unsigned long long uint64_t
Definition stdint.h:13
__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")

References __asm__(), __unused, __volatile__(), and data.

Referenced by PROVIDE_IOAPI().

◆ i386_writeq()

__unused void i386_writeq ( uint64_t data,
volatile uint64_t * io_addr )
static

Write 64-bit qword to memory-mapped device.

Parameters
dataValue to write
io_addrI/O address

This routine uses MMX instructions.

Definition at line 127 of file x86_io.c.

127 {
128 __asm__ __volatile__ ( "pushl %%edx\n\t"
129 "pushl %%eax\n\t"
130 "movq (%%esp), %%mm0\n\t"
131 "movq %%mm0, (%1)\n\t"
132 "popl %%eax\n\t"
133 "popl %%edx\n\t"
134 "emms\n\t"
135 : : "A" ( data ), "r" ( io_addr ) );
136}

References __asm__(), __unused, __volatile__(), and data.

Referenced by PROVIDE_IOAPI().

◆ PROVIDE_IOAPI_INLINE() [1/22]

PROVIDE_IOAPI_INLINE ( x86 ,
phys_to_bus  )

References phys_to_bus().

◆ PROVIDE_IOAPI_INLINE() [2/22]

PROVIDE_IOAPI_INLINE ( x86 ,
bus_to_phys  )

References bus_to_phys().

◆ PROVIDE_IOAPI_INLINE() [3/22]

PROVIDE_IOAPI_INLINE ( x86 ,
readb  )

References readb.

◆ PROVIDE_IOAPI_INLINE() [4/22]

PROVIDE_IOAPI_INLINE ( x86 ,
readw  )

References readw.

◆ PROVIDE_IOAPI_INLINE() [5/22]

PROVIDE_IOAPI_INLINE ( x86 ,
readl  )

References readl.

◆ PROVIDE_IOAPI_INLINE() [6/22]

PROVIDE_IOAPI_INLINE ( x86 ,
writeb  )

References writeb.

◆ PROVIDE_IOAPI_INLINE() [7/22]

PROVIDE_IOAPI_INLINE ( x86 ,
writew  )

References writew.

◆ PROVIDE_IOAPI_INLINE() [8/22]

PROVIDE_IOAPI_INLINE ( x86 ,
writel  )

References writel.

◆ PROVIDE_IOAPI_INLINE() [9/22]

PROVIDE_IOAPI_INLINE ( x86 ,
inb  )

References inb.

◆ PROVIDE_IOAPI_INLINE() [10/22]

PROVIDE_IOAPI_INLINE ( x86 ,
inw  )

References inw.

◆ PROVIDE_IOAPI_INLINE() [11/22]

PROVIDE_IOAPI_INLINE ( x86 ,
inl  )

References inl.

◆ PROVIDE_IOAPI_INLINE() [12/22]

PROVIDE_IOAPI_INLINE ( x86 ,
outb  )

References outb.

◆ PROVIDE_IOAPI_INLINE() [13/22]

PROVIDE_IOAPI_INLINE ( x86 ,
outw  )

References outw.

◆ PROVIDE_IOAPI_INLINE() [14/22]

PROVIDE_IOAPI_INLINE ( x86 ,
outl  )

References outl.

◆ PROVIDE_IOAPI_INLINE() [15/22]

PROVIDE_IOAPI_INLINE ( x86 ,
insb  )

References insb.

◆ PROVIDE_IOAPI_INLINE() [16/22]

PROVIDE_IOAPI_INLINE ( x86 ,
insw  )

References insw.

◆ PROVIDE_IOAPI_INLINE() [17/22]

PROVIDE_IOAPI_INLINE ( x86 ,
insl  )

References insl.

◆ PROVIDE_IOAPI_INLINE() [18/22]

PROVIDE_IOAPI_INLINE ( x86 ,
outsb  )

References outsb.

◆ PROVIDE_IOAPI_INLINE() [19/22]

PROVIDE_IOAPI_INLINE ( x86 ,
outsw  )

References outsw.

◆ PROVIDE_IOAPI_INLINE() [20/22]

PROVIDE_IOAPI_INLINE ( x86 ,
outsl  )

References outsl.

◆ PROVIDE_IOAPI_INLINE() [21/22]

PROVIDE_IOAPI_INLINE ( x86 ,
iodelay  )

References iodelay().

◆ PROVIDE_IOAPI_INLINE() [22/22]

PROVIDE_IOAPI_INLINE ( x86 ,
mb  )

References mb(), readq, and writeq.

◆ PROVIDE_IOAPI() [1/8]

PROVIDE_IOAPI ( x86 ,
readq ,
i386_readq  )

References i386_readq(), and readq.

◆ PROVIDE_IOAPI() [2/8]

PROVIDE_IOAPI ( x86 ,
writeq ,
i386_writeq  )

References i386_writeq(), and writeq.

◆ PROVIDE_IOAPI() [3/8]

PROVIDE_IOAPI ( x86 ,
ioread8 ,
x86_ioread8  )

References ioread8.

◆ PROVIDE_IOAPI() [4/8]

PROVIDE_IOAPI ( x86 ,
ioread16 ,
x86_ioread16  )

References ioread16.

◆ PROVIDE_IOAPI() [5/8]

PROVIDE_IOAPI ( x86 ,
ioread32 ,
x86_ioread32  )

References ioread32.

◆ PROVIDE_IOAPI() [6/8]

PROVIDE_IOAPI ( x86 ,
iowrite8 ,
x86_iowrite8  )

References iowrite8.

◆ PROVIDE_IOAPI() [7/8]

PROVIDE_IOAPI ( x86 ,
iowrite16 ,
x86_iowrite16  )

References iowrite16.

◆ PROVIDE_IOAPI() [8/8]

PROVIDE_IOAPI ( x86 ,
iowrite32 ,
x86_iowrite32  )

References iowrite32.