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