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