coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
io.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef __ARCH_IO_H__
4 #define __ARCH_IO_H__
5 
6 #include <stdint.h>
7 
8 /*
9  * This file contains the definitions for the x86 IO instructions
10  * inb/inw/inl/outb/outw/outl and the "string versions" of the same
11  * (insb/insw/insl/outsb/outsw/outsl).
12  */
13 static inline void outb(uint8_t value, uint16_t port)
14 {
15  __asm__ __volatile__ ("outb %b0, %w1" : : "a" (value), "Nd" (port));
16 }
17 
18 static inline void outw(uint16_t value, uint16_t port)
19 {
20  __asm__ __volatile__ ("outw %w0, %w1" : : "a" (value), "Nd" (port));
21 }
22 
23 static inline void outl(uint32_t value, uint16_t port)
24 {
25  __asm__ __volatile__ ("outl %0, %w1" : : "a" (value), "Nd" (port));
26 }
27 
28 static inline uint8_t inb(uint16_t port)
29 {
30  uint8_t value;
31  __asm__ __volatile__ ("inb %w1, %b0" : "=a"(value) : "Nd" (port));
32  return value;
33 }
34 
35 static inline uint16_t inw(uint16_t port)
36 {
38  __asm__ __volatile__ ("inw %w1, %w0" : "=a"(value) : "Nd" (port));
39  return value;
40 }
41 
42 static inline uint32_t inl(uint16_t port)
43 {
45  __asm__ __volatile__ ("inl %w1, %0" : "=a"(value) : "Nd" (port));
46  return value;
47 }
48 
49 static inline void outsb(uint16_t port, const void *addr, unsigned long count)
50 {
51  __asm__ __volatile__ (
52  "cld ; rep ; outsb "
53  : "=S" (addr), "=c" (count)
54  : "d"(port), "0"(addr), "1" (count)
55  );
56 }
57 
58 static inline void outsw(uint16_t port, const void *addr, unsigned long count)
59 {
60  __asm__ __volatile__ (
61  "cld ; rep ; outsw "
62  : "=S" (addr), "=c" (count)
63  : "d"(port), "0"(addr), "1" (count)
64  );
65 }
66 
67 static inline void outsl(uint16_t port, const void *addr, unsigned long count)
68 {
69  __asm__ __volatile__ (
70  "cld ; rep ; outsl "
71  : "=S" (addr), "=c" (count)
72  : "d"(port), "0"(addr), "1" (count)
73  );
74 }
75 
76 static inline void insb(uint16_t port, void *addr, unsigned long count)
77 {
78  __asm__ __volatile__ (
79  "cld ; rep ; insb "
80  : "=D" (addr), "=c" (count)
81  : "d"(port), "0"(addr), "1" (count)
82  : "memory"
83  );
84 }
85 
86 static inline void insw(uint16_t port, void *addr, unsigned long count)
87 {
88  __asm__ __volatile__ (
89  "cld ; rep ; insw "
90  : "=D" (addr), "=c" (count)
91  : "d"(port), "0"(addr), "1" (count)
92  : "memory"
93  );
94 }
95 
96 static inline void insl(uint16_t port, void *addr, unsigned long count)
97 {
98  __asm__ __volatile__ (
99  "cld ; rep ; insl "
100  : "=D" (addr), "=c" (count)
101  : "d"(port), "0"(addr), "1" (count)
102  : "memory"
103  );
104 }
105 
106 #endif
pte_t value
Definition: mmu.c:91
static uint8_t inb(uint16_t port)
Definition: io.h:28
static void outb(uint8_t value, uint16_t port)
Definition: io.h:13
static void insb(uint16_t port, void *addr, unsigned long count)
Definition: io.h:76
static void outsw(uint16_t port, const void *addr, unsigned long count)
Definition: io.h:58
static void outw(uint16_t value, uint16_t port)
Definition: io.h:18
static void insl(uint16_t port, void *addr, unsigned long count)
Definition: io.h:96
static void outsb(uint16_t port, const void *addr, unsigned long count)
Definition: io.h:49
static uint32_t inl(uint16_t port)
Definition: io.h:42
static uint16_t inw(uint16_t port)
Definition: io.h:35
static void outl(uint32_t value, uint16_t port)
Definition: io.h:23
static void insw(uint16_t port, void *addr, unsigned long count)
Definition: io.h:86
static void outsl(uint16_t port, const void *addr, unsigned long count)
Definition: io.h:67
static u32 addr
Definition: cirrus.c:14
port
Definition: i915.h:29
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
unsigned char uint8_t
Definition: stdint.h:8
#define count