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