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