]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibMsc.c
cfe5ddff4394b4a6305825f049b56bba0ae413d0
[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, 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 #if _MSC_EXTENSIONS
26
27 //
28 // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics
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 _ReadWriteBarrier ();
75 return (UINT8)_inp ((UINT16)Port);
76 }
77
78 /**
79 Writes an 8-bit I/O port.
80
81 Writes the 8-bit I/O port specified by Port with the value specified by Value
82 and returns Value. This function must guarantee that all I/O read and write
83 operations are serialized.
84
85 If 8-bit I/O port operations are not supported, then ASSERT().
86
87 @param Port The I/O port to write.
88 @param Value The value to write to the I/O port.
89
90 @return The value written the I/O port.
91
92 **/
93 UINT8
94 EFIAPI
95 IoWrite8 (
96 IN UINTN Port,
97 IN UINT8 Value
98 )
99 {
100 _ReadWriteBarrier ();
101 return (UINT8)_outp ((UINT16)Port, Value);
102 }
103
104 /**
105 Reads a 16-bit I/O port.
106
107 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
108 This function must guarantee that all I/O read and write operations are
109 serialized.
110
111 If 16-bit I/O port operations are not supported, then ASSERT().
112
113 @param Port The I/O port to read.
114
115 @return The value read.
116
117 **/
118 UINT16
119 EFIAPI
120 IoRead16 (
121 IN UINTN Port
122 )
123 {
124 ASSERT ((Port & 1) == 0);
125 _ReadWriteBarrier ();
126 return _inpw((UINT16)Port);
127 }
128
129 /**
130 Writes a 16-bit I/O port.
131
132 Writes the 16-bit I/O port specified by Port with the value specified by Value
133 and returns Value. This function must guarantee that all I/O read and write
134 operations are serialized.
135
136 If 16-bit I/O port operations are not supported, then ASSERT().
137
138 @param Port The I/O port to write.
139 @param Value The value to write to the I/O port.
140
141 @return The value written the I/O port.
142
143 **/
144 UINT16
145 EFIAPI
146 IoWrite16 (
147 IN UINTN Port,
148 IN UINT16 Value
149 )
150 {
151 ASSERT ((Port & 1) == 0);
152 _ReadWriteBarrier ();
153 return _outpw ((UINT16)Port, Value);
154 }
155
156 /**
157 Reads a 32-bit I/O port.
158
159 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
160 This function must guarantee that all I/O read and write operations are
161 serialized.
162
163 If 32-bit I/O port operations are not supported, then ASSERT().
164
165 @param Port The I/O port to read.
166
167 @return The value read.
168
169 **/
170 UINT32
171 EFIAPI
172 IoRead32 (
173 IN UINTN Port
174 )
175 {
176 ASSERT ((Port & 3) == 0);
177 _ReadWriteBarrier ();
178 return _inpd((UINT16)Port);
179 }
180
181 /**
182 Writes a 32-bit I/O port.
183
184 Writes the 32-bit I/O port specified by Port with the value specified by Value
185 and returns Value. This function must guarantee that all I/O read and write
186 operations are serialized.
187
188 If 32-bit I/O port operations are not supported, then ASSERT().
189
190 @param Port The I/O port to write.
191 @param Value The value to write to the I/O port.
192
193 @return The value written the I/O port.
194
195 **/
196 UINT32
197 EFIAPI
198 IoWrite32 (
199 IN UINTN Port,
200 IN UINT32 Value
201 )
202 {
203 ASSERT ((Port & 3) == 0);
204 _ReadWriteBarrier ();
205 return _outpd ((UINT16)Port, Value);
206 }
207
208
209 /**
210 Reads an 8-bit MMIO register.
211
212 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
213 returned. This function must guarantee that all MMIO read and write
214 operations are serialized.
215
216 If 8-bit MMIO register operations are not supported, then ASSERT().
217
218 @param Address The MMIO register to read.
219
220 @return The value read.
221
222 **/
223 UINT8
224 EFIAPI
225 MmioRead8 (
226 IN UINTN Address
227 )
228 {
229 _ReadWriteBarrier ();
230 return *(volatile UINT8 *)Address;
231 }
232
233 /**
234 Writes an 8-bit MMIO register.
235
236 Writes the 8-bit MMIO register specified by Address with the value specified
237 by Value and returns Value. This function must guarantee that all MMIO read
238 and write operations are serialized.
239
240 If 8-bit MMIO register operations are not supported, then ASSERT().
241
242 @param Address The MMIO register to write.
243 @param Value The value to write to the MMIO register.
244
245 **/
246 UINT8
247 EFIAPI
248 MmioWrite8 (
249 IN UINTN Address,
250 IN UINT8 Value
251 )
252 {
253 _ReadWriteBarrier ();
254 return *(volatile UINT8 *)Address = Value;
255 }
256
257 /**
258 Reads a 16-bit MMIO register.
259
260 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
261 returned. This function must guarantee that all MMIO read and write
262 operations are serialized.
263
264 If 16-bit MMIO register operations are not supported, then ASSERT().
265
266 @param Address The MMIO register to read.
267
268 @return The value read.
269
270 **/
271 UINT16
272 EFIAPI
273 MmioRead16 (
274 IN UINTN Address
275 )
276 {
277 ASSERT ((Address & 1) == 0);
278 _ReadWriteBarrier ();
279 return *(volatile UINT16 *)Address;
280 }
281
282 /**
283 Writes a 16-bit MMIO register.
284
285 Writes the 16-bit MMIO register specified by Address with the value specified
286 by Value and returns Value. This function must guarantee that all MMIO read
287 and write operations are serialized.
288
289 If 16-bit MMIO register operations are not supported, then ASSERT().
290
291 @param Address The MMIO register to write.
292 @param Value The value to write to the MMIO register.
293
294 **/
295 UINT16
296 EFIAPI
297 MmioWrite16 (
298 IN UINTN Address,
299 IN UINT16 Value
300 )
301 {
302 ASSERT ((Address & 1) == 0);
303 _ReadWriteBarrier ();
304 return *(volatile UINT16 *)Address = Value;
305 }
306
307 /**
308 Reads a 32-bit MMIO register.
309
310 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
311 returned. This function must guarantee that all MMIO read and write
312 operations are serialized.
313
314 If 32-bit MMIO register operations are not supported, then ASSERT().
315
316 @param Address The MMIO register to read.
317
318 @return The value read.
319
320 **/
321 UINT32
322 EFIAPI
323 MmioRead32 (
324 IN UINTN Address
325 )
326 {
327 ASSERT ((Address & 3) == 0);
328 _ReadWriteBarrier ();
329 return *(volatile UINT32 *)Address;
330 }
331
332 /**
333 Writes a 32-bit MMIO register.
334
335 Writes the 32-bit MMIO register specified by Address with the value specified
336 by Value and returns Value. This function must guarantee that all MMIO read
337 and write operations are serialized.
338
339 If 32-bit MMIO register operations are not supported, then ASSERT().
340
341 @param Address The MMIO register to write.
342 @param Value The value to write to the MMIO register.
343
344 **/
345 UINT32
346 EFIAPI
347 MmioWrite32 (
348 IN UINTN Address,
349 IN UINT32 Value
350 )
351 {
352 ASSERT ((Address & 3) == 0);
353 _ReadWriteBarrier ();
354 return *(volatile UINT32 *)Address = Value;
355 }
356
357 /**
358 Reads a 64-bit MMIO register.
359
360 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
361 returned. This function must guarantee that all MMIO read and write
362 operations are serialized.
363
364 If 64-bit MMIO register operations are not supported, then ASSERT().
365
366 @param Address The MMIO register to read.
367
368 @return The value read.
369
370 **/
371 UINT64
372 EFIAPI
373 MmioRead64 (
374 IN UINTN Address
375 )
376 {
377 ASSERT ((Address & 7) == 0);
378 _ReadWriteBarrier ();
379 return *(volatile UINT64 *)Address;
380 }
381
382 /**
383 Writes a 64-bit MMIO register.
384
385 Writes the 64-bit MMIO register specified by Address with the value specified
386 by Value and returns Value. This function must guarantee that all MMIO read
387 and write operations are serialized.
388
389 If 64-bit MMIO register operations are not supported, then ASSERT().
390
391 @param Address The MMIO register to write.
392 @param Value The value to write to the MMIO register.
393
394 **/
395 UINT64
396 EFIAPI
397 MmioWrite64 (
398 IN UINTN Address,
399 IN UINT64 Value
400 )
401 {
402 ASSERT ((Address & 7) == 0);
403 _ReadWriteBarrier ();
404 return *(volatile UINT64 *)Address = Value;
405 }
406
407 #endif