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