]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseIoLibIntrinsic/IoLibMsc.c
remove unnecessary comments introduced by tools from MdePkg. The regular express...
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLibMsc.c
CommitLineData
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
11 Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
12 All rights reserved. This program and the accompanying materials\r
13 are licensed and made available under the terms and conditions of the BSD License\r
14 which accompanies this distribution. The full text of the license may be found at\r
15 http://opensource.org/licenses/bsd-license.php\r
16\r
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
19\r
e1f414b6 20**/\r
21\r
22\r
1efcc4ae 23\r
f734a10a 24#include "BaseIoLibIntrinsicInternal.h"\r
e1f414b6 25\r
26//\r
42eedea9 27// Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.\r
e1f414b6 28//\r
42eedea9 29\r
e1f414b6 30int _inp (unsigned short port);\r
31unsigned short _inpw (unsigned short port);\r
32unsigned long _inpd (unsigned short port);\r
33int _outp (unsigned short port, int databyte );\r
34unsigned short _outpw (unsigned short port, unsigned short dataword );\r
35unsigned long _outpd (unsigned short port, unsigned long dataword );\r
36void _ReadWriteBarrier (void);\r
37\r
38#pragma intrinsic(_inp)\r
39#pragma intrinsic(_inpw)\r
40#pragma intrinsic(_inpd)\r
41#pragma intrinsic(_outp)\r
42#pragma intrinsic(_outpw)\r
43#pragma intrinsic(_outpd)\r
44#pragma intrinsic(_ReadWriteBarrier)\r
986352be 45\r
e1f414b6 46//\r
47// _ReadWriteBarrier() forces memory reads and writes to complete at the point\r
48// in the call. This is only a hint to the compiler and does emit code.\r
49// In past versions of the compiler, _ReadWriteBarrier was enforced only\r
50// locally and did not affect functions up the call tree. In Visual C++\r
51// 2005, _ReadWriteBarrier is enforced all the way up the call tree.\r
52//\r
53\r
54/**\r
55 Reads an 8-bit I/O port.\r
56\r
57 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r
58 This function must guarantee that all I/O read and write operations are\r
59 serialized.\r
60\r
61 If 8-bit I/O port operations are not supported, then ASSERT().\r
62\r
63 @param Port The I/O port to read.\r
64\r
38bbd3d9 65 @return The value read from Port.\r
e1f414b6 66\r
67**/\r
68UINT8\r
69EFIAPI\r
70IoRead8 (\r
71 IN UINTN Port\r
72 )\r
73{\r
74 UINT8 Value;\r
75\r
76 _ReadWriteBarrier ();\r
77 Value = (UINT8)_inp ((UINT16)Port);\r
78 _ReadWriteBarrier ();\r
79 return Value;\r
80}\r
81\r
82/**\r
83 Writes an 8-bit I/O port.\r
84\r
85 Writes the 8-bit I/O port specified by Port with the value specified by Value\r
86 and returns Value. This function must guarantee that all I/O read and write\r
87 operations are serialized.\r
88\r
89 If 8-bit I/O port operations are not supported, then ASSERT().\r
90\r
91 @param Port The I/O port to write.\r
92 @param Value The value to write to the I/O port.\r
93\r
94 @return The value written the I/O port.\r
95\r
96**/\r
97UINT8\r
98EFIAPI\r
99IoWrite8 (\r
100 IN UINTN Port,\r
101 IN UINT8 Value\r
102 )\r
103{\r
104 _ReadWriteBarrier ();\r
105 (UINT8)_outp ((UINT16)Port, Value);\r
106 _ReadWriteBarrier ();\r
107 return Value;\r
108}\r
109\r
110/**\r
111 Reads a 16-bit I/O port.\r
112\r
113 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r
114 This function must guarantee that all I/O read and write operations are\r
115 serialized.\r
116\r
117 If 16-bit I/O port operations are not supported, then ASSERT().\r
118\r
119 @param Port The I/O port to read.\r
120\r
38bbd3d9 121 @return The value read from Port.\r
e1f414b6 122\r
123**/\r
124UINT16\r
125EFIAPI\r
126IoRead16 (\r
127 IN UINTN Port\r
128 )\r
129{\r
130 UINT16 Value;\r
131\r
132 ASSERT ((Port & 1) == 0);\r
133 _ReadWriteBarrier ();\r
134 Value = _inpw ((UINT16)Port);\r
135 _ReadWriteBarrier ();\r
136 return Value;\r
137}\r
138\r
139/**\r
140 Writes a 16-bit I/O port.\r
141\r
142 Writes the 16-bit I/O port specified by Port with the value specified by Value\r
143 and returns Value. This function must guarantee that all I/O read and write\r
144 operations are serialized.\r
145\r
146 If 16-bit I/O port operations are not supported, then ASSERT().\r
147\r
148 @param Port The I/O port to write.\r
149 @param Value The value to write to the I/O port.\r
150\r
151 @return The value written the I/O port.\r
152\r
153**/\r
154UINT16\r
155EFIAPI\r
156IoWrite16 (\r
157 IN UINTN Port,\r
158 IN UINT16 Value\r
159 )\r
160{\r
161 ASSERT ((Port & 1) == 0);\r
162 _ReadWriteBarrier ();\r
163 _outpw ((UINT16)Port, Value);\r
164 _ReadWriteBarrier ();\r
165 return Value;\r
166}\r
167\r
168/**\r
169 Reads a 32-bit I/O port.\r
170\r
171 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r
172 This function must guarantee that all I/O read and write operations are\r
173 serialized.\r
174\r
175 If 32-bit I/O port operations are not supported, then ASSERT().\r
176\r
177 @param Port The I/O port to read.\r
178\r
38bbd3d9 179 @return The value read from Port.\r
e1f414b6 180\r
181**/\r
182UINT32\r
183EFIAPI\r
184IoRead32 (\r
185 IN UINTN Port\r
186 )\r
187{\r
188 UINT32 Value;\r
189\r
190 ASSERT ((Port & 3) == 0);\r
191 _ReadWriteBarrier ();\r
192 Value = _inpd ((UINT16)Port);\r
193 _ReadWriteBarrier ();\r
194 return Value;\r
195}\r
196\r
197/**\r
198 Writes a 32-bit I/O port.\r
199\r
200 Writes the 32-bit I/O port specified by Port with the value specified by Value\r
201 and returns Value. This function must guarantee that all I/O read and write\r
202 operations are serialized.\r
203\r
204 If 32-bit I/O port operations are not supported, then ASSERT().\r
205\r
206 @param Port The I/O port to write.\r
207 @param Value The value to write to the I/O port.\r
208\r
209 @return The value written the I/O port.\r
210\r
211**/\r
212UINT32\r
213EFIAPI\r
214IoWrite32 (\r
215 IN UINTN Port,\r
216 IN UINT32 Value\r
217 )\r
218{\r
219 ASSERT ((Port & 3) == 0);\r
220 _ReadWriteBarrier ();\r
221 _outpd ((UINT16)Port, Value);\r
222 _ReadWriteBarrier ();\r
223 return Value;\r
224}\r
225\r
226\r
227/**\r
228 Reads an 8-bit MMIO register.\r
229\r
230 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is\r
231 returned. This function must guarantee that all MMIO read and write\r
232 operations are serialized.\r
233\r
234 If 8-bit MMIO register operations are not supported, then ASSERT().\r
235\r
236 @param Address The MMIO register to read.\r
237\r
38bbd3d9 238 @return The value read from Address.\r
e1f414b6 239\r
240**/\r
241UINT8\r
242EFIAPI\r
243MmioRead8 (\r
244 IN UINTN Address\r
245 )\r
246{\r
247 UINT8 Value;\r
248\r
249 Value = *(volatile UINT8*)Address;\r
250 return Value;\r
251}\r
252\r
253/**\r
254 Writes an 8-bit MMIO register.\r
255\r
256 Writes the 8-bit MMIO register specified by Address with the value specified\r
257 by Value and returns Value. This function must guarantee that all MMIO read\r
258 and write operations are serialized.\r
259\r
260 If 8-bit MMIO register operations are not supported, then ASSERT().\r
261\r
262 @param Address The MMIO register to write.\r
263 @param Value The value to write to the MMIO register.\r
38bbd3d9 264 \r
265 @return The value written to the Mmio. It equals to the input\r
266 Value instead of the actual value read back from the\r
267 Mmio.\r
268 \r
e1f414b6 269**/\r
270UINT8\r
271EFIAPI\r
272MmioWrite8 (\r
273 IN UINTN Address,\r
274 IN UINT8 Value\r
275 )\r
276{\r
277 return *(volatile UINT8*)Address = Value;\r
278}\r
279\r
280/**\r
281 Reads a 16-bit MMIO register.\r
282\r
283 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is\r
284 returned. This function must guarantee that all MMIO read and write\r
285 operations are serialized.\r
286\r
287 If 16-bit MMIO register operations are not supported, then ASSERT().\r
288\r
289 @param Address The MMIO register to read.\r
290\r
38bbd3d9 291 @return The value read from Address.\r
e1f414b6 292\r
293**/\r
294UINT16\r
295EFIAPI\r
296MmioRead16 (\r
297 IN UINTN Address\r
298 )\r
299{\r
300 UINT16 Value;\r
301\r
302 ASSERT ((Address & 1) == 0);\r
303 Value = *(volatile UINT16*)Address;\r
304 return Value;\r
305}\r
306\r
307/**\r
308 Writes a 16-bit MMIO register.\r
309\r
310 Writes the 16-bit MMIO register specified by Address with the value specified\r
311 by Value and returns Value. This function must guarantee that all MMIO read\r
312 and write operations are serialized.\r
313\r
314 If 16-bit MMIO register operations are not supported, then ASSERT().\r
315\r
316 @param Address The MMIO register to write.\r
317 @param Value The value to write to the MMIO register.\r
38bbd3d9 318 \r
319 @return The value read from the Mmio after wrote specified\r
320 Value.\r
e1f414b6 321\r
322**/\r
323UINT16\r
324EFIAPI\r
325MmioWrite16 (\r
326 IN UINTN Address,\r
327 IN UINT16 Value\r
328 )\r
329{\r
330 ASSERT ((Address & 1) == 0);\r
331 return *(volatile UINT16*)Address = Value;\r
332}\r
333\r
334/**\r
335 Reads a 32-bit MMIO register.\r
336\r
337 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is\r
338 returned. This function must guarantee that all MMIO read and write\r
339 operations are serialized.\r
340\r
341 If 32-bit MMIO register operations are not supported, then ASSERT().\r
342\r
343 @param Address The MMIO register to read.\r
344\r
38bbd3d9 345 @return The value read from Address.\r
e1f414b6 346\r
347**/\r
348UINT32\r
349EFIAPI\r
350MmioRead32 (\r
351 IN UINTN Address\r
352 )\r
353{\r
354 UINT32 Value;\r
355\r
356 ASSERT ((Address & 3) == 0);\r
357 Value = *(volatile UINT32*)Address;\r
358 return Value;\r
359}\r
360\r
361/**\r
362 Writes a 32-bit MMIO register.\r
363\r
364 Writes the 32-bit MMIO register specified by Address with the value specified\r
365 by Value and returns Value. This function must guarantee that all MMIO read\r
366 and write operations are serialized.\r
367\r
368 If 32-bit MMIO register operations are not supported, then ASSERT().\r
369\r
370 @param Address The MMIO register to write.\r
371 @param Value The value to write to the MMIO register.\r
38bbd3d9 372 \r
373 @return The value written to the Mmio. It equals to the input\r
374 Value instead of the actual value read back from the\r
375 Mmio.\r
e1f414b6 376\r
377**/\r
378UINT32\r
379EFIAPI\r
380MmioWrite32 (\r
381 IN UINTN Address,\r
382 IN UINT32 Value\r
383 )\r
384{\r
385 ASSERT ((Address & 3) == 0);\r
386 return *(volatile UINT32*)Address = Value;\r
387}\r
388\r
389/**\r
390 Reads a 64-bit MMIO register.\r
391\r
392 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is\r
393 returned. This function must guarantee that all MMIO read and write\r
394 operations are serialized.\r
395\r
396 If 64-bit MMIO register operations are not supported, then ASSERT().\r
397\r
398 @param Address The MMIO register to read.\r
399\r
38bbd3d9 400 @return The value read from Address.\r
e1f414b6 401\r
402**/\r
403UINT64\r
404EFIAPI\r
405MmioRead64 (\r
406 IN UINTN Address\r
407 )\r
408{\r
409 UINT64 Value;\r
410\r
411 ASSERT ((Address & 7) == 0);\r
412 Value = *(volatile UINT64*)Address;\r
413 return Value;\r
414}\r
415\r
416/**\r
417 Writes a 64-bit MMIO register.\r
418\r
419 Writes the 64-bit MMIO register specified by Address with the value specified\r
420 by Value and returns Value. This function must guarantee that all MMIO read\r
421 and write operations are serialized.\r
422\r
423 If 64-bit MMIO register operations are not supported, then ASSERT().\r
424\r
425 @param Address The MMIO register to write.\r
426 @param Value The value to write to the MMIO register.\r
427\r
38bbd3d9 428 @return The value written to the Mmio. It equals to the input\r
429 Value instead of the actual value read back from the\r
430 Mmio.\r
431 \r
e1f414b6 432**/\r
433UINT64\r
434EFIAPI\r
435MmioWrite64 (\r
436 IN UINTN Address,\r
437 IN UINT64 Value\r
438 )\r
439{\r
440 ASSERT ((Address & 7) == 0);\r
441 return *(volatile UINT64*)Address = Value;\r
442}\r
443\r