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