]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseIoLibIntrinsic/IoLibMsc.c
Removed cross references from PciCf8Lib and PciExpressLib class to PciLib class.
[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
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
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
2ce31132 74 _ReadWriteBarrier ();\r
878ddf1f 75 return (UINT8)_inp ((UINT16)Port);\r
76}\r
77\r
78/**\r
79 Writes an 8-bit I/O port.\r
80\r
81 Writes the 8-bit I/O port specified by Port with the value specified by Value\r
82 and returns Value. This function must guarantee that all I/O read and write\r
83 operations are serialized.\r
84\r
85 If 8-bit I/O port operations are not supported, then ASSERT().\r
86\r
87 @param Port The I/O port to write.\r
88 @param Value The value to write to the I/O port.\r
89\r
90 @return The value written the I/O port.\r
91\r
92**/\r
93UINT8\r
94EFIAPI\r
95IoWrite8 (\r
96 IN UINTN Port,\r
97 IN UINT8 Value\r
98 )\r
99{\r
2ce31132 100 _ReadWriteBarrier ();\r
878ddf1f 101 return (UINT8)_outp ((UINT16)Port, Value);\r
102}\r
103\r
104/**\r
105 Reads a 16-bit I/O port.\r
106\r
107 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r
108 This function must guarantee that all I/O read and write operations are\r
109 serialized.\r
110\r
111 If 16-bit I/O port operations are not supported, then ASSERT().\r
112\r
113 @param Port The I/O port to read.\r
114\r
115 @return The value read.\r
116\r
117**/\r
118UINT16\r
119EFIAPI\r
120IoRead16 (\r
121 IN UINTN Port\r
122 )\r
123{\r
124 ASSERT ((Port & 1) == 0);\r
2ce31132 125 _ReadWriteBarrier ();\r
878ddf1f 126 return _inpw((UINT16)Port);\r
127}\r
128\r
129/**\r
130 Writes a 16-bit I/O port.\r
131\r
132 Writes the 16-bit I/O port specified by Port with the value specified by Value\r
133 and returns Value. This function must guarantee that all I/O read and write\r
134 operations are serialized.\r
135\r
136 If 16-bit I/O port operations are not supported, then ASSERT().\r
137\r
138 @param Port The I/O port to write.\r
139 @param Value The value to write to the I/O port.\r
140\r
141 @return The value written the I/O port.\r
142\r
143**/\r
144UINT16\r
145EFIAPI\r
146IoWrite16 (\r
147 IN UINTN Port,\r
148 IN UINT16 Value\r
149 )\r
150{\r
151 ASSERT ((Port & 1) == 0);\r
2ce31132 152 _ReadWriteBarrier ();\r
878ddf1f 153 return _outpw ((UINT16)Port, Value);\r
154}\r
155\r
156/**\r
157 Reads a 32-bit I/O port.\r
158\r
159 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r
160 This function must guarantee that all I/O read and write operations are\r
161 serialized.\r
162\r
163 If 32-bit I/O port operations are not supported, then ASSERT().\r
164\r
165 @param Port The I/O port to read.\r
166\r
167 @return The value read.\r
168\r
169**/\r
170UINT32\r
171EFIAPI\r
172IoRead32 (\r
173 IN UINTN Port\r
174 )\r
175{\r
176 ASSERT ((Port & 3) == 0);\r
2ce31132 177 _ReadWriteBarrier ();\r
878ddf1f 178 return _inpd((UINT16)Port);\r
179}\r
180\r
181/**\r
182 Writes a 32-bit I/O port.\r
183\r
184 Writes the 32-bit I/O port specified by Port with the value specified by Value\r
185 and returns Value. This function must guarantee that all I/O read and write\r
186 operations are serialized.\r
187\r
188 If 32-bit I/O port operations are not supported, then ASSERT().\r
189\r
190 @param Port The I/O port to write.\r
191 @param Value The value to write to the I/O port.\r
192\r
193 @return The value written the I/O port.\r
194\r
195**/\r
196UINT32\r
197EFIAPI\r
198IoWrite32 (\r
199 IN UINTN Port,\r
200 IN UINT32 Value\r
201 )\r
202{\r
203 ASSERT ((Port & 3) == 0);\r
2ce31132 204 _ReadWriteBarrier ();\r
878ddf1f 205 return _outpd ((UINT16)Port, Value);\r
206}\r
207\r
2ce31132 208\r
209/**\r
210 Reads an 8-bit MMIO register.\r
211\r
212 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is\r
213 returned. This function must guarantee that all MMIO read and write\r
214 operations are serialized.\r
215\r
216 If 8-bit MMIO register operations are not supported, then ASSERT().\r
217\r
218 @param Address The MMIO register to read.\r
219\r
220 @return The value read.\r
221\r
222**/\r
223UINT8\r
224EFIAPI\r
225MmioRead8 (\r
226 IN UINTN Address\r
227 )\r
228{\r
229 _ReadWriteBarrier ();\r
230 return *(volatile UINT8 *)Address;\r
231}\r
232\r
233/**\r
234 Writes an 8-bit MMIO register.\r
235\r
236 Writes the 8-bit MMIO register specified by Address with the value specified\r
237 by Value and returns Value. This function must guarantee that all MMIO read\r
238 and write operations are serialized.\r
239\r
240 If 8-bit MMIO register operations are not supported, then ASSERT().\r
241\r
242 @param Address The MMIO register to write.\r
243 @param Value The value to write to the MMIO register.\r
244\r
245**/\r
246UINT8\r
247EFIAPI\r
248MmioWrite8 (\r
249 IN UINTN Address,\r
250 IN UINT8 Value\r
251 )\r
252{\r
253 _ReadWriteBarrier ();\r
254 return *(volatile UINT8 *)Address = Value;\r
255}\r
256\r
257/**\r
258 Reads a 16-bit MMIO register.\r
259\r
260 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is\r
261 returned. This function must guarantee that all MMIO read and write\r
262 operations are serialized.\r
263\r
264 If 16-bit MMIO register operations are not supported, then ASSERT().\r
265\r
266 @param Address The MMIO register to read.\r
267\r
268 @return The value read.\r
269\r
270**/\r
271UINT16\r
272EFIAPI\r
273MmioRead16 (\r
274 IN UINTN Address\r
275 )\r
276{\r
277 ASSERT ((Address & 1) == 0);\r
278 _ReadWriteBarrier ();\r
279 return *(volatile UINT16 *)Address;\r
280}\r
281\r
282/**\r
283 Writes a 16-bit MMIO register.\r
284\r
285 Writes the 16-bit MMIO register specified by Address with the value specified\r
286 by Value and returns Value. This function must guarantee that all MMIO read\r
287 and write 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 write.\r
292 @param Value The value to write to the MMIO register.\r
293\r
294**/\r
295UINT16\r
296EFIAPI\r
297MmioWrite16 (\r
298 IN UINTN Address,\r
299 IN UINT16 Value\r
300 )\r
301{\r
302 ASSERT ((Address & 1) == 0);\r
303 _ReadWriteBarrier ();\r
304 return *(volatile UINT16 *)Address = Value;\r
305}\r
306\r
307/**\r
308 Reads a 32-bit MMIO register.\r
309\r
310 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is\r
311 returned. This function must guarantee that all MMIO read and write\r
312 operations are serialized.\r
313\r
314 If 32-bit MMIO register operations are not supported, then ASSERT().\r
315\r
316 @param Address The MMIO register to read.\r
317\r
318 @return The value read.\r
319\r
320**/\r
321UINT32\r
322EFIAPI\r
323MmioRead32 (\r
324 IN UINTN Address\r
325 )\r
326{\r
327 ASSERT ((Address & 3) == 0);\r
328 _ReadWriteBarrier ();\r
329 return *(volatile UINT32 *)Address;\r
330}\r
331\r
332/**\r
333 Writes a 32-bit MMIO register.\r
334\r
335 Writes the 32-bit MMIO register specified by Address with the value specified\r
336 by Value and returns Value. This function must guarantee that all MMIO read\r
337 and write operations are serialized.\r
338\r
339 If 32-bit MMIO register operations are not supported, then ASSERT().\r
340\r
341 @param Address The MMIO register to write.\r
342 @param Value The value to write to the MMIO register.\r
343\r
344**/\r
345UINT32\r
346EFIAPI\r
347MmioWrite32 (\r
348 IN UINTN Address,\r
349 IN UINT32 Value\r
350 )\r
351{\r
352 ASSERT ((Address & 3) == 0);\r
353 _ReadWriteBarrier ();\r
354 return *(volatile UINT32 *)Address = Value;\r
355}\r
356\r
357/**\r
358 Reads a 64-bit MMIO register.\r
359\r
360 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is\r
361 returned. This function must guarantee that all MMIO read and write\r
362 operations are serialized.\r
363\r
364 If 64-bit MMIO register operations are not supported, then ASSERT().\r
365\r
366 @param Address The MMIO register to read.\r
367\r
368 @return The value read.\r
369\r
370**/\r
371UINT64\r
372EFIAPI\r
373MmioRead64 (\r
374 IN UINTN Address\r
375 )\r
376{\r
377 ASSERT ((Address & 7) == 0);\r
378 _ReadWriteBarrier ();\r
379 return *(volatile UINT64 *)Address;\r
380}\r
381\r
382/**\r
383 Writes a 64-bit MMIO register.\r
384\r
385 Writes the 64-bit MMIO register specified by Address with the value specified\r
386 by Value and returns Value. This function must guarantee that all MMIO read\r
387 and write operations are serialized.\r
388\r
389 If 64-bit MMIO register operations are not supported, then ASSERT().\r
390\r
391 @param Address The MMIO register to write.\r
392 @param Value The value to write to the MMIO register.\r
393\r
394**/\r
395UINT64\r
396EFIAPI\r
397MmioWrite64 (\r
398 IN UINTN Address,\r
399 IN UINT64 Value\r
400 )\r
401{\r
402 ASSERT ((Address & 7) == 0);\r
403 _ReadWriteBarrier ();\r
404 return *(volatile UINT64 *)Address = Value;\r
405}\r
406\r
878ddf1f 407#endif\r