]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseIoLibIntrinsic/IoLibMsc.c
1. Added ReadWriteBarrier() before and after each I/O read/write function.
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLibMsc.c
CommitLineData
878ddf1f 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, 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
20 Module Name: IoLibMsc.c\r
21\r
22**/\r
23\r
24\r
25#if _MSC_EXTENSIONS\r
26\r
27//\r
28// Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics\r
29//\r
2ce31132 30int _inp (unsigned short port);\r
878ddf1f 31unsigned short _inpw (unsigned short port);\r
32unsigned long _inpd (unsigned short port);\r
33int _outp (unsigned short port, int databyte );\r
2ce31132 34unsigned short _outpw (unsigned short port, unsigned short dataword );\r
35unsigned long _outpd (unsigned short port, unsigned long dataword );\r
36void _ReadWriteBarrier (void);\r
878ddf1f 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
2ce31132 44#pragma intrinsic(_ReadWriteBarrier)\r
878ddf1f 45\r
2ce31132 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
cea9bda0 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
2ce31132 51// 2005, _ReadWriteBarrier is enforced all the way up the call tree.\r
52//\r
878ddf1f 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
65 @return The value read.\r
66\r
67**/\r
68UINT8\r
69EFIAPI\r
70IoRead8 (\r
71 IN UINTN Port\r
72 )\r
73{\r
cea9bda0 74 UINT8 Value;\r
75\r
76 _ReadWriteBarrier ();\r
77 Value = (UINT8)_inp ((UINT16)Port);\r
2ce31132 78 _ReadWriteBarrier ();\r
cea9bda0 79 return Value;\r
878ddf1f 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
2ce31132 104 _ReadWriteBarrier ();\r
cea9bda0 105 (UINT8)_outp ((UINT16)Port, Value);\r
106 _ReadWriteBarrier ();\r
107 return Value;\r
878ddf1f 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
121 @return The value read.\r
122\r
123**/\r
124UINT16\r
125EFIAPI\r
126IoRead16 (\r
127 IN UINTN Port\r
128 )\r
129{\r
cea9bda0 130 UINT16 Value;\r
131\r
878ddf1f 132 ASSERT ((Port & 1) == 0);\r
2ce31132 133 _ReadWriteBarrier ();\r
cea9bda0 134 Value = _inpw ((UINT16)Port);\r
135 _ReadWriteBarrier ();\r
136 return Value;\r
878ddf1f 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
2ce31132 162 _ReadWriteBarrier ();\r
cea9bda0 163 _outpw ((UINT16)Port, Value);\r
164 _ReadWriteBarrier ();\r
165 return Value;\r
878ddf1f 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
179 @return The value read.\r
180\r
181**/\r
182UINT32\r
183EFIAPI\r
184IoRead32 (\r
185 IN UINTN Port\r
186 )\r
187{\r
cea9bda0 188 UINT32 Value;\r
189\r
878ddf1f 190 ASSERT ((Port & 3) == 0);\r
2ce31132 191 _ReadWriteBarrier ();\r
cea9bda0 192 Value = _inpd ((UINT16)Port);\r
193 _ReadWriteBarrier ();\r
194 return Value;\r
878ddf1f 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
2ce31132 220 _ReadWriteBarrier ();\r
cea9bda0 221 _outpd ((UINT16)Port, Value);\r
222 _ReadWriteBarrier ();\r
223 return Value;\r
878ddf1f 224}\r
225\r
2ce31132 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
238 @return The value read.\r
239\r
240**/\r
241UINT8\r
242EFIAPI\r
243MmioRead8 (\r
244 IN UINTN Address\r
245 )\r
246{\r
cea9bda0 247 UINT8 Value;\r
248\r
249 Value = *(volatile UINT8*)Address;\r
250 return Value;\r
2ce31132 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
264\r
265**/\r
266UINT8\r
267EFIAPI\r
268MmioWrite8 (\r
269 IN UINTN Address,\r
270 IN UINT8 Value\r
271 )\r
272{\r
cea9bda0 273 return *(volatile UINT8*)Address = Value;\r
2ce31132 274}\r
275\r
276/**\r
277 Reads a 16-bit MMIO register.\r
278\r
279 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is\r
280 returned. This function must guarantee that all MMIO read and write\r
281 operations are serialized.\r
282\r
283 If 16-bit MMIO register operations are not supported, then ASSERT().\r
284\r
285 @param Address The MMIO register to read.\r
286\r
287 @return The value read.\r
288\r
289**/\r
290UINT16\r
291EFIAPI\r
292MmioRead16 (\r
293 IN UINTN Address\r
294 )\r
295{\r
cea9bda0 296 UINT16 Value;\r
297\r
2ce31132 298 ASSERT ((Address & 1) == 0);\r
cea9bda0 299 Value = *(volatile UINT16*)Address;\r
300 return Value;\r
2ce31132 301}\r
302\r
303/**\r
304 Writes a 16-bit MMIO register.\r
305\r
306 Writes the 16-bit MMIO register specified by Address with the value specified\r
307 by Value and returns Value. This function must guarantee that all MMIO read\r
308 and write operations are serialized.\r
309\r
310 If 16-bit MMIO register operations are not supported, then ASSERT().\r
311\r
312 @param Address The MMIO register to write.\r
313 @param Value The value to write to the MMIO register.\r
314\r
315**/\r
316UINT16\r
317EFIAPI\r
318MmioWrite16 (\r
319 IN UINTN Address,\r
320 IN UINT16 Value\r
321 )\r
322{\r
323 ASSERT ((Address & 1) == 0);\r
cea9bda0 324 return *(volatile UINT16*)Address = Value;\r
2ce31132 325}\r
326\r
327/**\r
328 Reads a 32-bit MMIO register.\r
329\r
330 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is\r
331 returned. This function must guarantee that all MMIO read and write\r
332 operations are serialized.\r
333\r
334 If 32-bit MMIO register operations are not supported, then ASSERT().\r
335\r
336 @param Address The MMIO register to read.\r
337\r
338 @return The value read.\r
339\r
340**/\r
341UINT32\r
342EFIAPI\r
343MmioRead32 (\r
344 IN UINTN Address\r
345 )\r
346{\r
cea9bda0 347 UINT32 Value;\r
348\r
2ce31132 349 ASSERT ((Address & 3) == 0);\r
cea9bda0 350 Value = *(volatile UINT32*)Address;\r
351 return Value;\r
2ce31132 352}\r
353\r
354/**\r
355 Writes a 32-bit MMIO register.\r
356\r
357 Writes the 32-bit MMIO register specified by Address with the value specified\r
358 by Value and returns Value. This function must guarantee that all MMIO read\r
359 and write operations are serialized.\r
360\r
361 If 32-bit MMIO register operations are not supported, then ASSERT().\r
362\r
363 @param Address The MMIO register to write.\r
364 @param Value The value to write to the MMIO register.\r
365\r
366**/\r
367UINT32\r
368EFIAPI\r
369MmioWrite32 (\r
370 IN UINTN Address,\r
371 IN UINT32 Value\r
372 )\r
373{\r
374 ASSERT ((Address & 3) == 0);\r
cea9bda0 375 return *(volatile UINT32*)Address = Value;\r
2ce31132 376}\r
377\r
378/**\r
379 Reads a 64-bit MMIO register.\r
380\r
381 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is\r
382 returned. This function must guarantee that all MMIO read and write\r
383 operations are serialized.\r
384\r
385 If 64-bit MMIO register operations are not supported, then ASSERT().\r
386\r
387 @param Address The MMIO register to read.\r
388\r
389 @return The value read.\r
390\r
391**/\r
392UINT64\r
393EFIAPI\r
394MmioRead64 (\r
395 IN UINTN Address\r
396 )\r
397{\r
cea9bda0 398 UINT64 Value;\r
399\r
2ce31132 400 ASSERT ((Address & 7) == 0);\r
cea9bda0 401 Value = *(volatile UINT64*)Address;\r
402 return Value;\r
2ce31132 403}\r
404\r
405/**\r
406 Writes a 64-bit MMIO register.\r
407\r
408 Writes the 64-bit MMIO register specified by Address with the value specified\r
409 by Value and returns Value. This function must guarantee that all MMIO read\r
410 and write operations are serialized.\r
411\r
412 If 64-bit MMIO register operations are not supported, then ASSERT().\r
413\r
414 @param Address The MMIO register to write.\r
415 @param Value The value to write to the MMIO register.\r
416\r
417**/\r
418UINT64\r
419EFIAPI\r
420MmioWrite64 (\r
421 IN UINTN Address,\r
422 IN UINT64 Value\r
423 )\r
424{\r
425 ASSERT ((Address & 7) == 0);\r
cea9bda0 426 return *(volatile UINT64*)Address = Value;\r
2ce31132 427}\r
428\r
878ddf1f 429#endif\r