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