]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibIcc.c
Code scrub:
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLibIcc.c
1 /** @file
2 I/O Library. This file has compiler specifics for ICC as there
3 is no ANSI C standard for doing IO.
4
5 Copyright (c) 2006 - 2007, Intel Corporation<BR> All rights
6 reserved. This program and the accompanying materials are
7 licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "BaseIoLibIntrinsicInternal.h"
17
18 /**
19 Reads an 8-bit MMIO register.
20
21 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
22 returned. This function must guarantee that all MMIO read and write
23 operations are serialized.
24
25 If 8-bit MMIO register operations are not supported, then ASSERT().
26
27 @param Address The MMIO register to read.
28
29 @return The value read from Address.
30
31 **/
32 UINT8
33 EFIAPI
34 MmioRead8 (
35 IN UINTN Address
36 )
37 {
38 return *(volatile UINT8*)Address;
39 }
40
41 /**
42 Writes an 8-bit MMIO register.
43
44 Writes the 8-bit MMIO register specified by Address with the value specified
45 by Value and returns Value. This function must guarantee that all MMIO read
46 and write operations are serialized.
47
48 If 8-bit MMIO register operations are not supported, then ASSERT().
49
50 @param Address The MMIO register to write.
51 @param Value The value to write to the MMIO register.
52
53 @return The value written to the Mmio. It equals to the input
54 Value instead of the actual value read back from the
55 Mmio.
56
57 **/
58 UINT8
59 EFIAPI
60 MmioWrite8 (
61 IN UINTN Address,
62 IN UINT8 Value
63 )
64 {
65 return *(volatile UINT8*)Address = Value;
66 }
67
68 /**
69 Reads a 16-bit MMIO register.
70
71 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
72 returned. This function must guarantee that all MMIO read and write
73 operations are serialized.
74
75 If 16-bit MMIO register operations are not supported, then ASSERT().
76
77 @param Address The MMIO register to read.
78
79 @return The value read from Address.
80
81 **/
82 UINT16
83 EFIAPI
84 MmioRead16 (
85 IN UINTN Address
86 )
87 {
88 ASSERT ((Address & 1) == 0);
89 return *(volatile UINT16*)Address;
90 }
91
92 /**
93 Writes a 16-bit MMIO register.
94
95 Writes the 16-bit MMIO register specified by Address with the value specified
96 by Value and returns Value. This function must guarantee that all MMIO read
97 and write operations are serialized.
98
99 If 16-bit MMIO register operations are not supported, then ASSERT().
100
101 @param Address The MMIO register to write.
102 @param Value The value to write to the MMIO register.
103
104 @return The value written to the Mmio. It equals to the input
105 Value instead of the actual value read back from the
106 Mmio.
107
108 **/
109 UINT16
110 EFIAPI
111 MmioWrite16 (
112 IN UINTN Address,
113 IN UINT16 Value
114 )
115 {
116 ASSERT ((Address & 1) == 0);
117 return *(volatile UINT16*)Address = Value;
118 }
119
120 /**
121 Reads a 32-bit MMIO register.
122
123 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
124 returned. This function must guarantee that all MMIO read and write
125 operations are serialized.
126
127 If 32-bit MMIO register operations are not supported, then ASSERT().
128
129 @param Address The MMIO register to read.
130
131 @return The value read from Address.
132
133 **/
134 UINT32
135 EFIAPI
136 MmioRead32 (
137 IN UINTN Address
138 )
139 {
140 ASSERT ((Address & 3) == 0);
141 return *(volatile UINT32*)Address;
142 }
143
144 /**
145 Writes a 32-bit MMIO register.
146
147 Writes the 32-bit MMIO register specified by Address with the value specified
148 by Value and returns Value. This function must guarantee that all MMIO read
149 and write operations are serialized.
150
151 If 32-bit MMIO register operations are not supported, then ASSERT().
152
153 @param Address The MMIO register to write.
154 @param Value The value to write to the MMIO register.
155
156 @return The value written to the Mmio. It equals to the input
157 Value instead of the actual value read back from the
158 Mmio.
159
160 **/
161 UINT32
162 EFIAPI
163 MmioWrite32 (
164 IN UINTN Address,
165 IN UINT32 Value
166 )
167 {
168 ASSERT ((Address & 3) == 0);
169 return *(volatile UINT32*)Address = Value;
170 }
171
172 /**
173 Reads a 64-bit MMIO register.
174
175 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
176 returned. This function must guarantee that all MMIO read and write
177 operations are serialized.
178
179 If 64-bit MMIO register operations are not supported, then ASSERT().
180
181 @param Address The MMIO register to read.
182
183 @return The value read from Address.
184
185 **/
186 UINT64
187 EFIAPI
188 MmioRead64 (
189 IN UINTN Address
190 )
191 {
192 ASSERT ((Address & 7) == 0);
193 return *(volatile UINT64*)Address;
194 }
195
196 /**
197 Writes a 64-bit MMIO register.
198
199 Writes the 64-bit MMIO register specified by Address with the value specified
200 by Value and returns Value. This function must guarantee that all MMIO read
201 and write operations are serialized.
202
203 If 64-bit MMIO register operations are not supported, then ASSERT().
204
205 @param Address The MMIO register to write.
206 @param Value The value to write to the MMIO register.
207
208 @return The value written to the Mmio. It equals to the input
209 Value instead of the actual value read back from the
210 Mmio.
211 **/
212 UINT64
213 EFIAPI
214 MmioWrite64 (
215 IN UINTN Address,
216 IN UINT64 Value
217 )
218 {
219 ASSERT ((Address & 7) == 0);
220 return *(volatile UINT64*)Address = Value;
221 }
222
223
224
225 /**
226 Reads an 8-bit I/O port.
227
228 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
229 This function must guarantee that all I/O read and write operations are
230 serialized.
231
232 If 8-bit I/O port operations are not supported, then ASSERT().
233
234 @param Port The I/O port to read.
235
236 @return The value read from Port.
237
238 **/
239 UINT8
240 EFIAPI
241 IoRead8 (
242 IN UINTN Port
243 )
244 {
245 UINT8 Data;
246
247 __asm {
248 mov dx, word ptr [Port]
249 in al, dx
250
251 mov Data, al
252 }
253 return Data;
254 }
255
256 /**
257 Writes an 8-bit I/O port.
258
259 Writes the 8-bit I/O port specified by Port with the value specified by Value
260 and returns Value. This function must guarantee that all I/O read and write
261 operations are serialized.
262
263 If 8-bit I/O port operations are not supported, then ASSERT().
264
265 @param Port The I/O port to write.
266 @param Value The value to write to the I/O port.
267
268 @return The value written to the I/O port. It equals to the input
269 Value instead of the actual value read back from the
270 I/O port.
271
272 **/
273 UINT8
274 EFIAPI
275 IoWrite8 (
276 IN UINTN Port,
277 IN UINT8 Value
278 )
279 {
280 __asm {
281 mov al, byte ptr [Value]
282 mov dx, word ptr [Port]
283 out dx, al
284 }
285 return Value;
286 }
287
288 /**
289 Reads a 16-bit I/O port.
290
291 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
292 This function must guarantee that all I/O read and write operations are
293 serialized.
294
295 If 16-bit I/O port operations are not supported, then ASSERT().
296
297 @param Port The I/O port to read.
298
299 @return The value read from Port.
300
301 **/
302 UINT16
303 EFIAPI
304 IoRead16 (
305 IN UINTN Port
306 )
307 {
308 UINT16 Data;
309
310 ASSERT ((Port & 1) == 0);
311
312 __asm {
313 mov dx, word ptr [Port]
314 in ax, dx
315 mov word ptr [Data], ax
316 }
317
318 return Data;
319 }
320
321 /**
322 Writes a 16-bit I/O port.
323
324 Writes the 16-bit I/O port specified by Port with the value specified by Value
325 and returns Value. This function must guarantee that all I/O read and write
326 operations are serialized.
327
328 If 16-bit I/O port operations are not supported, then ASSERT().
329
330 @param Port The I/O port to write.
331 @param Value The value to write to the I/O port.
332
333 @return The value written to the I/O port. It equals to the input
334 Value instead of the actual value read back from the
335 I/O port.
336
337 **/
338 UINT16
339 EFIAPI
340 IoWrite16 (
341 IN UINTN Port,
342 IN UINT16 Value
343 )
344 {
345 ASSERT ((Port & 1) == 0);
346
347 __asm {
348 mov ax, word ptr [Value]
349 mov dx, word ptr [Port]
350 out dx, ax
351 }
352
353 //
354 // Never reached return statement.
355 //
356 return Value;
357 }
358
359 /**
360 Reads a 32-bit I/O port.
361
362 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
363 This function must guarantee that all I/O read and write operations are
364 serialized.
365
366 If 32-bit I/O port operations are not supported, then ASSERT().
367
368 @param Port The I/O port to read.
369
370 @return The value read from Port.
371
372 **/
373 UINT32
374 EFIAPI
375 IoRead32 (
376 IN UINTN Port
377 )
378 {
379 UINT32 Data;
380
381 ASSERT ((Port & 3) == 0);
382
383 __asm {
384 mov dx, word ptr [Port]
385 in eax, dx
386 mov dword ptr [Data], eax
387 }
388
389 return Data;
390 }
391
392 /**
393 Writes a 32-bit I/O port.
394
395 Writes the 32-bit I/O port specified by Port with the value specified by Value
396 and returns Value. This function must guarantee that all I/O read and write
397 operations are serialized.
398
399 If 32-bit I/O port operations are not supported, then ASSERT().
400
401 @param Port The I/O port to write.
402 @param Value The value to write to the I/O port.
403
404 @return The value written to the I/O port. It equals to the input
405 Value instead of the actual value read back from the
406 I/O port.
407
408 **/
409 UINT32
410 EFIAPI
411 IoWrite32 (
412 IN UINTN Port,
413 IN UINT32 Value
414 )
415 {
416 ASSERT ((Port & 3) == 0);
417
418 __asm {
419 mov eax, dword ptr [Value]
420 mov dx, word ptr [Port]
421 out dx, eax
422 }
423
424 return Value;
425 }
426