]>
Commit | Line | Data |
---|---|---|
e1f414b6 | 1 | /** @file\r |
2 | I/O Library. This file has compiler specifics for Microsft C as there is no\r | |
3 | ANSI C standard for doing IO.\r | |
4 | \r | |
5 | MSC - uses intrinsic functions and the optimize will remove the function call\r | |
6 | overhead.\r | |
7 | \r | |
8 | We don't advocate putting compiler specifics in libraries or drivers but there\r | |
9 | is no other way to make this work.\r | |
10 | \r | |
38c8be12 | 11 | Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>\r |
9344f092 | 12 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
e1f414b6 | 13 | \r |
e1f414b6 | 14 | **/\r |
15 | \r | |
f734a10a | 16 | #include "BaseIoLibIntrinsicInternal.h"\r |
e1f414b6 | 17 | \r |
18 | //\r | |
42eedea9 | 19 | // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.\r |
e1f414b6 | 20 | //\r |
42eedea9 | 21 | \r |
2f88bd3a MK |
22 | int\r |
23 | _inp (\r | |
24 | unsigned short port\r | |
25 | );\r | |
26 | \r | |
27 | unsigned short\r | |
28 | _inpw (\r | |
29 | unsigned short port\r | |
30 | );\r | |
31 | \r | |
32 | unsigned long\r | |
33 | _inpd (\r | |
34 | unsigned short port\r | |
35 | );\r | |
36 | \r | |
37 | int\r | |
38 | _outp (\r | |
39 | unsigned short port,\r | |
40 | int databyte\r | |
41 | );\r | |
42 | \r | |
43 | unsigned short\r | |
44 | _outpw (\r | |
45 | unsigned short port,\r | |
46 | unsigned short dataword\r | |
47 | );\r | |
48 | \r | |
49 | unsigned long\r | |
50 | _outpd (\r | |
51 | unsigned short port,\r | |
52 | unsigned long dataword\r | |
53 | );\r | |
54 | \r | |
55 | void\r | |
56 | _ReadWriteBarrier (\r | |
57 | void\r | |
58 | );\r | |
e1f414b6 | 59 | \r |
60 | #pragma intrinsic(_inp)\r | |
61 | #pragma intrinsic(_inpw)\r | |
62 | #pragma intrinsic(_inpd)\r | |
63 | #pragma intrinsic(_outp)\r | |
64 | #pragma intrinsic(_outpw)\r | |
65 | #pragma intrinsic(_outpd)\r | |
66 | #pragma intrinsic(_ReadWriteBarrier)\r | |
986352be | 67 | \r |
e1f414b6 | 68 | //\r |
69 | // _ReadWriteBarrier() forces memory reads and writes to complete at the point\r | |
70 | // in the call. This is only a hint to the compiler and does emit code.\r | |
71 | // In past versions of the compiler, _ReadWriteBarrier was enforced only\r | |
72 | // locally and did not affect functions up the call tree. In Visual C++\r | |
73 | // 2005, _ReadWriteBarrier is enforced all the way up the call tree.\r | |
74 | //\r | |
75 | \r | |
76 | /**\r | |
77 | Reads an 8-bit I/O port.\r | |
78 | \r | |
79 | Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r | |
80 | This function must guarantee that all I/O read and write operations are\r | |
81 | serialized.\r | |
82 | \r | |
83 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
84 | \r | |
85 | @param Port The I/O port to read.\r | |
86 | \r | |
2281e7a9 | 87 | @return The value read.\r |
e1f414b6 | 88 | \r |
89 | **/\r | |
90 | UINT8\r | |
91 | EFIAPI\r | |
92 | IoRead8 (\r | |
2f88bd3a | 93 | IN UINTN Port\r |
e1f414b6 | 94 | )\r |
95 | {\r | |
2f88bd3a MK |
96 | UINT8 Value;\r |
97 | BOOLEAN Flag;\r | |
38c8be12 DB |
98 | \r |
99 | Flag = FilterBeforeIoRead (FilterWidth8, Port, &Value);\r | |
100 | if (Flag) {\r | |
101 | _ReadWriteBarrier ();\r | |
102 | Value = (UINT8)_inp ((UINT16)Port);\r | |
103 | _ReadWriteBarrier ();\r | |
104 | }\r | |
2f88bd3a | 105 | \r |
38c8be12 | 106 | FilterAfterIoRead (FilterWidth8, Port, &Value);\r |
e1f414b6 | 107 | \r |
e1f414b6 | 108 | return Value;\r |
109 | }\r | |
110 | \r | |
111 | /**\r | |
112 | Writes an 8-bit I/O port.\r | |
113 | \r | |
114 | Writes the 8-bit I/O port specified by Port with the value specified by Value\r | |
115 | and returns Value. This function must guarantee that all I/O read and write\r | |
116 | operations are serialized.\r | |
117 | \r | |
118 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
119 | \r | |
120 | @param Port The I/O port to write.\r | |
121 | @param Value The value to write to the I/O port.\r | |
122 | \r | |
35a17154 | 123 | @return The value written to the I/O port.\r |
e1f414b6 | 124 | \r |
125 | **/\r | |
126 | UINT8\r | |
127 | EFIAPI\r | |
128 | IoWrite8 (\r | |
2f88bd3a MK |
129 | IN UINTN Port,\r |
130 | IN UINT8 Value\r | |
e1f414b6 | 131 | )\r |
132 | {\r | |
2f88bd3a | 133 | BOOLEAN Flag;\r |
38c8be12 | 134 | \r |
2f88bd3a | 135 | Flag = FilterBeforeIoWrite (FilterWidth8, Port, &Value);\r |
38c8be12 DB |
136 | if (Flag) {\r |
137 | _ReadWriteBarrier ();\r | |
138 | (UINT8)_outp ((UINT16)Port, Value);\r | |
139 | _ReadWriteBarrier ();\r | |
140 | }\r | |
2f88bd3a | 141 | \r |
38c8be12 DB |
142 | FilterAfterIoWrite (FilterWidth8, Port, &Value);\r |
143 | \r | |
e1f414b6 | 144 | return Value;\r |
145 | }\r | |
146 | \r | |
147 | /**\r | |
148 | Reads a 16-bit I/O port.\r | |
149 | \r | |
150 | Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r | |
151 | This function must guarantee that all I/O read and write operations are\r | |
152 | serialized.\r | |
153 | \r | |
154 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
2281e7a9 | 155 | If Port is not aligned on a 16-bit boundary, then ASSERT().\r |
e1f414b6 | 156 | \r |
157 | @param Port The I/O port to read.\r | |
158 | \r | |
2281e7a9 | 159 | @return The value read.\r |
e1f414b6 | 160 | \r |
161 | **/\r | |
162 | UINT16\r | |
163 | EFIAPI\r | |
164 | IoRead16 (\r | |
2f88bd3a | 165 | IN UINTN Port\r |
e1f414b6 | 166 | )\r |
167 | {\r | |
2f88bd3a MK |
168 | UINT16 Value;\r |
169 | BOOLEAN Flag;\r | |
e1f414b6 | 170 | \r |
171 | ASSERT ((Port & 1) == 0);\r | |
38c8be12 DB |
172 | \r |
173 | Flag = FilterBeforeIoRead (FilterWidth16, Port, &Value);\r | |
174 | if (Flag) {\r | |
175 | _ReadWriteBarrier ();\r | |
176 | Value = _inpw ((UINT16)Port);\r | |
177 | _ReadWriteBarrier ();\r | |
178 | }\r | |
2f88bd3a | 179 | \r |
38c8be12 DB |
180 | FilterBeforeIoRead (FilterWidth16, Port, &Value);\r |
181 | \r | |
e1f414b6 | 182 | return Value;\r |
183 | }\r | |
184 | \r | |
185 | /**\r | |
186 | Writes a 16-bit I/O port.\r | |
187 | \r | |
188 | Writes the 16-bit I/O port specified by Port with the value specified by Value\r | |
189 | and returns Value. This function must guarantee that all I/O read and write\r | |
190 | operations are serialized.\r | |
191 | \r | |
192 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
2281e7a9 | 193 | If Port is not aligned on a 16-bit boundary, then ASSERT().\r |
9095d37b | 194 | \r |
e1f414b6 | 195 | @param Port The I/O port to write.\r |
196 | @param Value The value to write to the I/O port.\r | |
197 | \r | |
35a17154 | 198 | @return The value written to the I/O port.\r |
e1f414b6 | 199 | \r |
200 | **/\r | |
201 | UINT16\r | |
202 | EFIAPI\r | |
203 | IoWrite16 (\r | |
2f88bd3a MK |
204 | IN UINTN Port,\r |
205 | IN UINT16 Value\r | |
e1f414b6 | 206 | )\r |
207 | {\r | |
2f88bd3a | 208 | BOOLEAN Flag;\r |
38c8be12 | 209 | \r |
e1f414b6 | 210 | ASSERT ((Port & 1) == 0);\r |
38c8be12 | 211 | \r |
2f88bd3a | 212 | Flag = FilterBeforeIoWrite (FilterWidth16, Port, &Value);\r |
38c8be12 DB |
213 | if (Flag) {\r |
214 | _ReadWriteBarrier ();\r | |
215 | _outpw ((UINT16)Port, Value);\r | |
216 | _ReadWriteBarrier ();\r | |
217 | }\r | |
2f88bd3a | 218 | \r |
38c8be12 DB |
219 | FilterAfterIoWrite (FilterWidth16, Port, &Value);\r |
220 | \r | |
e1f414b6 | 221 | return Value;\r |
222 | }\r | |
223 | \r | |
224 | /**\r | |
225 | Reads a 32-bit I/O port.\r | |
226 | \r | |
227 | Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r | |
228 | This function must guarantee that all I/O read and write operations are\r | |
229 | serialized.\r | |
230 | \r | |
231 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
2281e7a9 | 232 | If Port is not aligned on a 32-bit boundary, then ASSERT().\r |
9095d37b | 233 | \r |
e1f414b6 | 234 | @param Port The I/O port to read.\r |
235 | \r | |
2281e7a9 | 236 | @return The value read.\r |
e1f414b6 | 237 | \r |
238 | **/\r | |
239 | UINT32\r | |
240 | EFIAPI\r | |
241 | IoRead32 (\r | |
2f88bd3a | 242 | IN UINTN Port\r |
e1f414b6 | 243 | )\r |
244 | {\r | |
2f88bd3a MK |
245 | UINT32 Value;\r |
246 | BOOLEAN Flag;\r | |
e1f414b6 | 247 | \r |
248 | ASSERT ((Port & 3) == 0);\r | |
38c8be12 | 249 | \r |
2f88bd3a | 250 | Flag = FilterBeforeIoRead (FilterWidth32, Port, &Value);\r |
38c8be12 DB |
251 | if (Flag) {\r |
252 | _ReadWriteBarrier ();\r | |
253 | Value = _inpd ((UINT16)Port);\r | |
254 | _ReadWriteBarrier ();\r | |
255 | }\r | |
2f88bd3a | 256 | \r |
38c8be12 DB |
257 | FilterAfterIoRead (FilterWidth32, Port, &Value);\r |
258 | \r | |
e1f414b6 | 259 | return Value;\r |
260 | }\r | |
261 | \r | |
262 | /**\r | |
263 | Writes a 32-bit I/O port.\r | |
264 | \r | |
265 | Writes the 32-bit I/O port specified by Port with the value specified by Value\r | |
266 | and returns Value. This function must guarantee that all I/O read and write\r | |
267 | operations are serialized.\r | |
268 | \r | |
269 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
2281e7a9 | 270 | If Port is not aligned on a 32-bit boundary, then ASSERT().\r |
9095d37b | 271 | \r |
e1f414b6 | 272 | @param Port The I/O port to write.\r |
273 | @param Value The value to write to the I/O port.\r | |
274 | \r | |
35a17154 | 275 | @return The value written to the I/O port.\r |
e1f414b6 | 276 | \r |
277 | **/\r | |
278 | UINT32\r | |
279 | EFIAPI\r | |
280 | IoWrite32 (\r | |
2f88bd3a MK |
281 | IN UINTN Port,\r |
282 | IN UINT32 Value\r | |
e1f414b6 | 283 | )\r |
284 | {\r | |
2f88bd3a | 285 | BOOLEAN Flag;\r |
38c8be12 | 286 | \r |
e1f414b6 | 287 | ASSERT ((Port & 3) == 0);\r |
38c8be12 | 288 | \r |
2f88bd3a | 289 | Flag = FilterBeforeIoWrite (FilterWidth32, Port, &Value);\r |
38c8be12 DB |
290 | if (Flag) {\r |
291 | _ReadWriteBarrier ();\r | |
292 | _outpd ((UINT16)Port, Value);\r | |
293 | _ReadWriteBarrier ();\r | |
294 | }\r | |
2f88bd3a | 295 | \r |
38c8be12 DB |
296 | FilterAfterIoWrite (FilterWidth32, Port, &Value);\r |
297 | \r | |
e1f414b6 | 298 | return Value;\r |
299 | }\r |