]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibGcc.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLibGcc.c
1 /** @file
2 I/O Library. This file has compiler specifics for GCC as there is no
3 ANSI C standard for doing IO.
4
5 GCC - uses EFIAPI assembler. __asm__ calls GAS. __volatile__ makes sure the
6 compiler puts the assembler in this exact location. The complex GNUC
7 operations are not optimzed. It would be possible to also write these
8 with EFIAPI assembler.
9
10 We don't advocate putting compiler specifics in libraries or drivers but there
11 is no other way to make this work.
12
13 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
14 SPDX-License-Identifier: BSD-2-Clause-Patent
15
16 **/
17
18
19 #include "BaseIoLibIntrinsicInternal.h"
20
21 /**
22 Reads an 8-bit I/O port.
23
24 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
25 This function must guarantee that all I/O read and write operations are
26 serialized.
27
28 If 8-bit I/O port operations are not supported, then ASSERT().
29
30 @param Port The I/O port to read.
31
32 @return The value read.
33
34 **/
35 __inline__
36 UINT8
37 EFIAPI
38 IoRead8 (
39 IN UINTN Port
40 )
41 {
42 UINT8 Data;
43
44 __asm__ __volatile__ ("inb %w1,%b0" : "=a" (Data) : "d" ((UINT16)Port));
45 return Data;
46 }
47
48 /**
49 Writes an 8-bit I/O port.
50
51 Writes the 8-bit I/O port specified by Port with the value specified by Value
52 and returns Value. This function must guarantee that all I/O read and write
53 operations are serialized.
54
55 If 8-bit I/O port operations are not supported, then ASSERT().
56
57 @param Port The I/O port to write.
58 @param Value The value to write to the I/O port.
59
60 @return The value written the I/O port.
61
62 **/
63 __inline__
64 UINT8
65 EFIAPI
66 IoWrite8 (
67 IN UINTN Port,
68 IN UINT8 Value
69 )
70 {
71 __asm__ __volatile__ ("outb %b0,%w1" : : "a" (Value), "d" ((UINT16)Port));
72 return Value;;
73 }
74
75 /**
76 Reads a 16-bit I/O port.
77
78 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
79 This function must guarantee that all I/O read and write operations are
80 serialized.
81
82 If 16-bit I/O port operations are not supported, then ASSERT().
83 If Port is not aligned on a 16-bit boundary, then ASSERT().
84
85 @param Port The I/O port to read.
86
87 @return The value read.
88
89 **/
90 __inline__
91 UINT16
92 EFIAPI
93 IoRead16 (
94 IN UINTN Port
95 )
96 {
97 UINT16 Data;
98
99 ASSERT ((Port & 1) == 0);
100 __asm__ __volatile__ ("inw %w1,%w0" : "=a" (Data) : "d" ((UINT16)Port));
101 return Data;
102 }
103
104 /**
105 Writes a 16-bit I/O port.
106
107 Writes the 16-bit I/O port specified by Port with the value specified by Value
108 and returns Value. This function must guarantee that all I/O read and write
109 operations are serialized.
110
111 If 16-bit I/O port operations are not supported, then ASSERT().
112 If Port is not aligned on a 16-bit boundary, then ASSERT().
113
114 @param Port The I/O port to write.
115 @param Value The value to write to the I/O port.
116
117 @return The value written the I/O port.
118
119 **/
120 __inline__
121 UINT16
122 EFIAPI
123 IoWrite16 (
124 IN UINTN Port,
125 IN UINT16 Value
126 )
127 {
128 ASSERT ((Port & 1) == 0);
129 __asm__ __volatile__ ("outw %w0,%w1" : : "a" (Value), "d" ((UINT16)Port));
130 return Value;;
131 }
132
133 /**
134 Reads a 32-bit I/O port.
135
136 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
137 This function must guarantee that all I/O read and write operations are
138 serialized.
139
140 If 32-bit I/O port operations are not supported, then ASSERT().
141 If Port is not aligned on a 32-bit boundary, then ASSERT().
142
143 @param Port The I/O port to read.
144
145 @return The value read.
146
147 **/
148 __inline__
149 UINT32
150 EFIAPI
151 IoRead32 (
152 IN UINTN Port
153 )
154 {
155 UINT32 Data;
156
157 ASSERT ((Port & 3) == 0);
158 __asm__ __volatile__ ("inl %w1,%0" : "=a" (Data) : "d" ((UINT16)Port));
159 return Data;
160 }
161
162 /**
163 Writes a 32-bit I/O port.
164
165 Writes the 32-bit I/O port specified by Port with the value specified by Value
166 and returns Value. This function must guarantee that all I/O read and write
167 operations are serialized.
168
169 If 32-bit I/O port operations are not supported, then ASSERT().
170 If Port is not aligned on a 32-bit boundary, then ASSERT().
171
172 @param Port The I/O port to write.
173 @param Value The value to write to the I/O port.
174
175 @return The value written the I/O port.
176
177 **/
178 __inline__
179 UINT32
180 EFIAPI
181 IoWrite32 (
182 IN UINTN Port,
183 IN UINT32 Value
184 )
185 {
186 ASSERT ((Port & 3) == 0);
187 __asm__ __volatile__ ("outl %0,%w1" : : "a" (Value), "d" ((UINT16)Port));
188 return Value;
189 }
190