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