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