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