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