]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibMsc.c
Synchronize the h files with c files.
[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.
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 If Port is not aligned on a 16-bit boundary, then ASSERT().
119
120 @param Port The I/O port to read.
121
122 @return The value read.
123
124 **/
125 UINT16
126 EFIAPI
127 IoRead16 (
128 IN UINTN Port
129 )
130 {
131 UINT16 Value;
132
133 ASSERT ((Port & 1) == 0);
134 _ReadWriteBarrier ();
135 Value = _inpw ((UINT16)Port);
136 _ReadWriteBarrier ();
137 return Value;
138 }
139
140 /**
141 Writes a 16-bit I/O port.
142
143 Writes the 16-bit I/O port specified by Port with the value specified by Value
144 and returns Value. This function must guarantee that all I/O read and write
145 operations are serialized.
146
147 If 16-bit I/O port operations are not supported, then ASSERT().
148 If Port is not aligned on a 16-bit boundary, 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 If Port is not aligned on a 32-bit boundary, then ASSERT().
179
180 @param Port The I/O port to read.
181
182 @return The value read.
183
184 **/
185 UINT32
186 EFIAPI
187 IoRead32 (
188 IN UINTN Port
189 )
190 {
191 UINT32 Value;
192
193 ASSERT ((Port & 3) == 0);
194 _ReadWriteBarrier ();
195 Value = _inpd ((UINT16)Port);
196 _ReadWriteBarrier ();
197 return Value;
198 }
199
200 /**
201 Writes a 32-bit I/O port.
202
203 Writes the 32-bit I/O port specified by Port with the value specified by Value
204 and returns Value. This function must guarantee that all I/O read and write
205 operations are serialized.
206
207 If 32-bit I/O port operations are not supported, then ASSERT().
208 If Port is not aligned on a 32-bit boundary, then ASSERT().
209
210 @param Port The I/O port to write.
211 @param Value The value to write to the I/O port.
212
213 @return The value written the I/O port.
214
215 **/
216 UINT32
217 EFIAPI
218 IoWrite32 (
219 IN UINTN Port,
220 IN UINT32 Value
221 )
222 {
223 ASSERT ((Port & 3) == 0);
224 _ReadWriteBarrier ();
225 _outpd ((UINT16)Port, Value);
226 _ReadWriteBarrier ();
227 return Value;
228 }
229
230
231 /**
232 Reads an 8-bit MMIO register.
233
234 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
235 returned. This function must guarantee that all MMIO read and write
236 operations are serialized.
237
238 If 8-bit MMIO register operations are not supported, then ASSERT().
239
240 @param Address The MMIO register to read.
241
242 @return The value read.
243
244 **/
245 UINT8
246 EFIAPI
247 MmioRead8 (
248 IN UINTN Address
249 )
250 {
251 UINT8 Value;
252
253 Value = *(volatile UINT8*)Address;
254 return Value;
255 }
256
257 /**
258 Writes an 8-bit MMIO register.
259
260 Writes the 8-bit MMIO register specified by Address with the value specified
261 by Value and returns Value. This function must guarantee that all MMIO read
262 and write operations are serialized.
263
264 If 8-bit MMIO register operations are not supported, then ASSERT().
265
266 @param Address The MMIO register to write.
267 @param Value The value to write to the MMIO register.
268
269 @return Value.
270
271 **/
272 UINT8
273 EFIAPI
274 MmioWrite8 (
275 IN UINTN Address,
276 IN UINT8 Value
277 )
278 {
279 return *(volatile UINT8*)Address = Value;
280 }
281
282 /**
283 Reads a 16-bit MMIO register.
284
285 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
286 returned. This function must guarantee that all MMIO read and write
287 operations are serialized.
288
289 If 16-bit MMIO register operations are not supported, then ASSERT().
290 If Address is not aligned on a 16-bit boundary, then ASSERT().
291
292 @param Address The MMIO register to read.
293
294 @return The value read.
295
296 **/
297 UINT16
298 EFIAPI
299 MmioRead16 (
300 IN UINTN Address
301 )
302 {
303 UINT16 Value;
304
305 ASSERT ((Address & 1) == 0);
306 Value = *(volatile UINT16*)Address;
307 return Value;
308 }
309
310 /**
311 Writes a 16-bit MMIO register.
312
313 Writes the 16-bit MMIO register specified by Address with the value specified
314 by Value and returns Value. This function must guarantee that all MMIO read
315 and write operations are serialized.
316
317 If 16-bit MMIO register operations are not supported, then ASSERT().
318 If Address is not aligned on a 16-bit boundary, then ASSERT().
319
320 @param Address The MMIO register to write.
321 @param Value The value to write to the MMIO register.
322
323 @return Value.
324
325 **/
326 UINT16
327 EFIAPI
328 MmioWrite16 (
329 IN UINTN Address,
330 IN UINT16 Value
331 )
332 {
333 ASSERT ((Address & 1) == 0);
334 return *(volatile UINT16*)Address = Value;
335 }
336
337 /**
338 Reads a 32-bit MMIO register.
339
340 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
341 returned. This function must guarantee that all MMIO read and write
342 operations are serialized.
343
344 If 32-bit MMIO register operations are not supported, then ASSERT().
345 If Address is not aligned on a 32-bit boundary, then ASSERT().
346
347 @param Address The MMIO register to read.
348
349 @return The value read.
350
351 **/
352 UINT32
353 EFIAPI
354 MmioRead32 (
355 IN UINTN Address
356 )
357 {
358 UINT32 Value;
359
360 ASSERT ((Address & 3) == 0);
361 Value = *(volatile UINT32*)Address;
362 return Value;
363 }
364
365 /**
366 Writes a 32-bit MMIO register.
367
368 Writes the 32-bit MMIO register specified by Address with the value specified
369 by Value and returns Value. This function must guarantee that all MMIO read
370 and write operations are serialized.
371
372 If 32-bit MMIO register operations are not supported, then ASSERT().
373 If Address is not aligned on a 32-bit boundary, then ASSERT().
374
375 @param Address The MMIO register to write.
376 @param Value The value to write to the MMIO register.
377
378 @return Value.
379
380 **/
381 UINT32
382 EFIAPI
383 MmioWrite32 (
384 IN UINTN Address,
385 IN UINT32 Value
386 )
387 {
388 ASSERT ((Address & 3) == 0);
389 return *(volatile UINT32*)Address = Value;
390 }
391
392 /**
393 Reads a 64-bit MMIO register.
394
395 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
396 returned. This function must guarantee that all MMIO read and write
397 operations are serialized.
398
399 If 64-bit MMIO register operations are not supported, then ASSERT().
400 If Address is not aligned on a 64-bit boundary, then ASSERT().
401
402 @param Address The MMIO register to read.
403
404 @return The value read.
405
406 **/
407 UINT64
408 EFIAPI
409 MmioRead64 (
410 IN UINTN Address
411 )
412 {
413 UINT64 Value;
414
415 ASSERT ((Address & 7) == 0);
416 Value = *(volatile UINT64*)Address;
417 return Value;
418 }
419
420 /**
421 Writes a 64-bit MMIO register.
422
423 Writes the 64-bit MMIO register specified by Address with the value specified
424 by Value and returns Value. This function must guarantee that all MMIO read
425 and write operations are serialized.
426
427 If 64-bit MMIO register operations are not supported, then ASSERT().
428 If Address is not aligned on a 64-bit boundary, then ASSERT().
429
430 @param Address The MMIO register to write.
431 @param Value The value to write to the MMIO register.
432
433 **/
434 UINT64
435 EFIAPI
436 MmioWrite64 (
437 IN UINTN Address,
438 IN UINT64 Value
439 )
440 {
441 ASSERT ((Address & 7) == 0);
442 return *(volatile UINT64*)Address = Value;
443 }
444