]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseIoLibIntrinsic/IoLibMsc.c
removed comments (and fix) compiler specific compile of .c files
[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
29// Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics\r
30//\r
31int _inp (unsigned short port);\r
32unsigned short _inpw (unsigned short port);\r
33unsigned long _inpd (unsigned short port);\r
34int _outp (unsigned short port, int databyte );\r
35unsigned short _outpw (unsigned short port, unsigned short dataword );\r
36unsigned long _outpd (unsigned short port, unsigned long dataword );\r
37void _ReadWriteBarrier (void);\r
38\r
dcab253b 39#ifdef _MSC_VER\r
e1f414b6 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
dcab253b 47#endif \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
67 @return The value read.\r
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
123 @return The value read.\r
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
181 @return The value read.\r
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
240 @return The value read.\r
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
266\r
267**/\r
268UINT8\r
269EFIAPI\r
270MmioWrite8 (\r
271 IN UINTN Address,\r
272 IN UINT8 Value\r
273 )\r
274{\r
275 return *(volatile UINT8*)Address = Value;\r
276}\r
277\r
278/**\r
279 Reads a 16-bit MMIO register.\r
280\r
281 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is\r
282 returned. This function must guarantee that all MMIO read and write\r
283 operations are serialized.\r
284\r
285 If 16-bit MMIO register operations are not supported, then ASSERT().\r
286\r
287 @param Address The MMIO register to read.\r
288\r
289 @return The value read.\r
290\r
291**/\r
292UINT16\r
293EFIAPI\r
294MmioRead16 (\r
295 IN UINTN Address\r
296 )\r
297{\r
298 UINT16 Value;\r
299\r
300 ASSERT ((Address & 1) == 0);\r
301 Value = *(volatile UINT16*)Address;\r
302 return Value;\r
303}\r
304\r
305/**\r
306 Writes a 16-bit MMIO register.\r
307\r
308 Writes the 16-bit MMIO register specified by Address with the value specified\r
309 by Value and returns Value. This function must guarantee that all MMIO read\r
310 and write operations are serialized.\r
311\r
312 If 16-bit MMIO register operations are not supported, then ASSERT().\r
313\r
314 @param Address The MMIO register to write.\r
315 @param Value The value to write to the MMIO register.\r
316\r
317**/\r
318UINT16\r
319EFIAPI\r
320MmioWrite16 (\r
321 IN UINTN Address,\r
322 IN UINT16 Value\r
323 )\r
324{\r
325 ASSERT ((Address & 1) == 0);\r
326 return *(volatile UINT16*)Address = Value;\r
327}\r
328\r
329/**\r
330 Reads a 32-bit MMIO register.\r
331\r
332 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is\r
333 returned. This function must guarantee that all MMIO read and write\r
334 operations are serialized.\r
335\r
336 If 32-bit MMIO register operations are not supported, then ASSERT().\r
337\r
338 @param Address The MMIO register to read.\r
339\r
340 @return The value read.\r
341\r
342**/\r
343UINT32\r
344EFIAPI\r
345MmioRead32 (\r
346 IN UINTN Address\r
347 )\r
348{\r
349 UINT32 Value;\r
350\r
351 ASSERT ((Address & 3) == 0);\r
352 Value = *(volatile UINT32*)Address;\r
353 return Value;\r
354}\r
355\r
356/**\r
357 Writes a 32-bit MMIO register.\r
358\r
359 Writes the 32-bit MMIO register specified by Address with the value specified\r
360 by Value and returns Value. This function must guarantee that all MMIO read\r
361 and write operations are serialized.\r
362\r
363 If 32-bit MMIO register operations are not supported, then ASSERT().\r
364\r
365 @param Address The MMIO register to write.\r
366 @param Value The value to write to the MMIO register.\r
367\r
368**/\r
369UINT32\r
370EFIAPI\r
371MmioWrite32 (\r
372 IN UINTN Address,\r
373 IN UINT32 Value\r
374 )\r
375{\r
376 ASSERT ((Address & 3) == 0);\r
377 return *(volatile UINT32*)Address = Value;\r
378}\r
379\r
380/**\r
381 Reads a 64-bit MMIO register.\r
382\r
383 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is\r
384 returned. This function must guarantee that all MMIO read and write\r
385 operations are serialized.\r
386\r
387 If 64-bit MMIO register operations are not supported, then ASSERT().\r
388\r
389 @param Address The MMIO register to read.\r
390\r
391 @return The value read.\r
392\r
393**/\r
394UINT64\r
395EFIAPI\r
396MmioRead64 (\r
397 IN UINTN Address\r
398 )\r
399{\r
400 UINT64 Value;\r
401\r
402 ASSERT ((Address & 7) == 0);\r
403 Value = *(volatile UINT64*)Address;\r
404 return Value;\r
405}\r
406\r
407/**\r
408 Writes a 64-bit MMIO register.\r
409\r
410 Writes the 64-bit MMIO register specified by Address with the value specified\r
411 by Value and returns Value. This function must guarantee that all MMIO read\r
412 and write operations are serialized.\r
413\r
414 If 64-bit MMIO register operations are not supported, then ASSERT().\r
415\r
416 @param Address The MMIO register to write.\r
417 @param Value The value to write to the MMIO register.\r
418\r
419**/\r
420UINT64\r
421EFIAPI\r
422MmioWrite64 (\r
423 IN UINTN Address,\r
424 IN UINT64 Value\r
425 )\r
426{\r
427 ASSERT ((Address & 7) == 0);\r
428 return *(volatile UINT64*)Address = Value;\r
429}\r
430\r