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