iPXE
Macros | Functions
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. More...
 
#define X86_IOREADX(_api_func, _suffix, _type)
 Read from I/O-mapped or memory-mapped device. More...
 
#define X86_IOWRITEX(_api_func, _suffix, _type)
 Write to I/O-mapped or memory-mapped device. More...
 

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. More...
 
static __unused void i386_writeq (uint64_t data, volatile uint64_t *io_addr)
 Write 64-bit qword to memory-mapped device. More...
 
 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 ); \
} \
}
struct option_descriptor read[1]
Definition: nvo_cmd.c:115
__be32 in[4]
Definition: CIB_PRM.h:35
unsigned long intptr_t
Definition: stdint.h:21
#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.

◆ 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 ); \
} \
}
unsigned long intptr_t
Definition: stdint.h:21
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define PIO_THRESHOLD
Threshold for port I/O-mapped addresses.
Definition: x86_io.c:60

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.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ X86_IOREADX() [1/3]

X86_IOREADX ( ioread8  ,
,
uint8_t   
)

◆ X86_IOREADX() [2/3]

X86_IOREADX ( ioread16  ,
,
uint16_t   
)

◆ X86_IOREADX() [3/3]

X86_IOREADX ( ioread32  ,
l  ,
uint32_t   
)

◆ X86_IOWRITEX() [1/3]

X86_IOWRITEX ( iowrite8  ,
,
uint8_t   
)

◆ X86_IOWRITEX() [2/3]

X86_IOWRITEX ( iowrite16  ,
,
uint16_t   
)

◆ X86_IOWRITEX() [3/3]

X86_IOWRITEX ( iowrite32  ,
l  ,
uint32_t   
)

◆ i386_readq()

static __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  {
107  uint64_t data;
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 }
unsigned long long uint64_t
Definition: stdint.h:13
__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))
__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")
uint8_t data[48]
Additional event data.
Definition: ena.h:22

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

◆ i386_writeq()

static __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 }
__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))
__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")
uint8_t data[48]
Additional event data.
Definition: ena.h:22

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

◆ PROVIDE_IOAPI_INLINE() [1/22]

PROVIDE_IOAPI_INLINE ( x86  ,
phys_to_bus   
)

◆ PROVIDE_IOAPI_INLINE() [2/22]

PROVIDE_IOAPI_INLINE ( x86  ,
bus_to_phys   
)

◆ PROVIDE_IOAPI_INLINE() [3/22]

PROVIDE_IOAPI_INLINE ( x86  ,
readb   
)

◆ PROVIDE_IOAPI_INLINE() [4/22]

PROVIDE_IOAPI_INLINE ( x86  ,
readw   
)

◆ PROVIDE_IOAPI_INLINE() [5/22]

PROVIDE_IOAPI_INLINE ( x86  ,
readl   
)

◆ PROVIDE_IOAPI_INLINE() [6/22]

PROVIDE_IOAPI_INLINE ( x86  ,
writeb   
)

◆ PROVIDE_IOAPI_INLINE() [7/22]

PROVIDE_IOAPI_INLINE ( x86  ,
writew   
)

◆ PROVIDE_IOAPI_INLINE() [8/22]

PROVIDE_IOAPI_INLINE ( x86  ,
writel   
)

◆ PROVIDE_IOAPI_INLINE() [9/22]

PROVIDE_IOAPI_INLINE ( x86  ,
inb   
)

◆ PROVIDE_IOAPI_INLINE() [10/22]

PROVIDE_IOAPI_INLINE ( x86  ,
inw   
)

◆ PROVIDE_IOAPI_INLINE() [11/22]

PROVIDE_IOAPI_INLINE ( x86  ,
inl   
)

◆ PROVIDE_IOAPI_INLINE() [12/22]

PROVIDE_IOAPI_INLINE ( x86  ,
outb   
)

◆ PROVIDE_IOAPI_INLINE() [13/22]

PROVIDE_IOAPI_INLINE ( x86  ,
outw   
)

◆ PROVIDE_IOAPI_INLINE() [14/22]

PROVIDE_IOAPI_INLINE ( x86  ,
outl   
)

◆ PROVIDE_IOAPI_INLINE() [15/22]

PROVIDE_IOAPI_INLINE ( x86  ,
insb   
)

◆ PROVIDE_IOAPI_INLINE() [16/22]

PROVIDE_IOAPI_INLINE ( x86  ,
insw   
)

◆ PROVIDE_IOAPI_INLINE() [17/22]

PROVIDE_IOAPI_INLINE ( x86  ,
insl   
)

◆ PROVIDE_IOAPI_INLINE() [18/22]

PROVIDE_IOAPI_INLINE ( x86  ,
outsb   
)

◆ PROVIDE_IOAPI_INLINE() [19/22]

PROVIDE_IOAPI_INLINE ( x86  ,
outsw   
)

◆ PROVIDE_IOAPI_INLINE() [20/22]

PROVIDE_IOAPI_INLINE ( x86  ,
outsl   
)

◆ PROVIDE_IOAPI_INLINE() [21/22]

PROVIDE_IOAPI_INLINE ( x86  ,
iodelay   
)

◆ PROVIDE_IOAPI_INLINE() [22/22]

PROVIDE_IOAPI_INLINE ( x86  ,
mb   
)

◆ PROVIDE_IOAPI() [1/8]

PROVIDE_IOAPI ( x86  ,
readq  ,
i386_readq   
)

◆ PROVIDE_IOAPI() [2/8]

PROVIDE_IOAPI ( x86  ,
writeq  ,
i386_writeq   
)

◆ PROVIDE_IOAPI() [3/8]

PROVIDE_IOAPI ( x86  ,
ioread8  ,
x86_ioread8   
)

◆ PROVIDE_IOAPI() [4/8]

PROVIDE_IOAPI ( x86  ,
ioread16  ,
x86_ioread16   
)

◆ PROVIDE_IOAPI() [5/8]

PROVIDE_IOAPI ( x86  ,
ioread32  ,
x86_ioread32   
)

◆ PROVIDE_IOAPI() [6/8]

PROVIDE_IOAPI ( x86  ,
iowrite8  ,
x86_iowrite8   
)

◆ PROVIDE_IOAPI() [7/8]

PROVIDE_IOAPI ( x86  ,
iowrite16  ,
x86_iowrite16   
)

◆ PROVIDE_IOAPI() [8/8]

PROVIDE_IOAPI ( x86  ,
iowrite32  ,
x86_iowrite32   
)