]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseIoLibIntrinsic/IoLibIcc.c
MdePkg: Clean up source files
[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
9095d37b 5 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
4dd6f840 6 This program and the accompanying materials are\r
d074a8e1 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
35a17154 9 http://opensource.org/licenses/bsd-license.php.\r
d074a8e1 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
d074a8e1 18/**\r
19 Reads an 8-bit I/O port.\r
20\r
21 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r
22 This function must guarantee that all I/O read and write operations are\r
23 serialized.\r
24\r
25 If 8-bit I/O port operations are not supported, then ASSERT().\r
26\r
27 @param Port The I/O port to read.\r
28\r
2281e7a9 29 @return The value read.\r
d074a8e1 30\r
31**/\r
32UINT8\r
33EFIAPI\r
34IoRead8 (\r
35 IN UINTN Port\r
36 )\r
37{\r
38 UINT8 Data;\r
39\r
40 __asm {\r
41 mov dx, word ptr [Port]\r
42 in al, dx\r
43\r
44 mov Data, al\r
45 }\r
46 return Data;\r
47}\r
48\r
49/**\r
50 Writes an 8-bit I/O port.\r
51\r
52 Writes the 8-bit I/O port specified by Port with the value specified by Value\r
53 and returns Value. This function must guarantee that all I/O read and write\r
54 operations are serialized.\r
55\r
56 If 8-bit I/O port operations are not supported, then ASSERT().\r
57\r
58 @param Port The I/O port to write.\r
59 @param Value The value to write to the I/O port.\r
60\r
2281e7a9 61 @return The value written the I/O port.\r
d074a8e1 62\r
63**/\r
64UINT8\r
65EFIAPI\r
66IoWrite8 (\r
67 IN UINTN Port,\r
68 IN UINT8 Value\r
69 )\r
70{\r
71 __asm {\r
72 mov al, byte ptr [Value]\r
73 mov dx, word ptr [Port]\r
74 out dx, al\r
75 }\r
9095d37b 76 return Value;\r
d074a8e1 77}\r
78\r
79/**\r
80 Reads a 16-bit I/O port.\r
81\r
82 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r
83 This function must guarantee that all I/O read and write operations are\r
84 serialized.\r
85\r
86 If 16-bit I/O port operations are not supported, then ASSERT().\r
2281e7a9 87 If Port is not aligned on a 16-bit boundary, then ASSERT().\r
d074a8e1 88\r
89 @param Port The I/O port to read.\r
90\r
2281e7a9 91 @return The value read.\r
d074a8e1 92\r
93**/\r
94UINT16\r
95EFIAPI\r
96IoRead16 (\r
97 IN UINTN Port\r
98 )\r
99{\r
100 UINT16 Data;\r
101\r
102 ASSERT ((Port & 1) == 0);\r
103\r
104 __asm {\r
105 mov dx, word ptr [Port]\r
106 in ax, dx\r
107 mov word ptr [Data], ax\r
108 }\r
109\r
110 return Data;\r
111}\r
112\r
113/**\r
114 Writes a 16-bit I/O port.\r
115\r
116 Writes the 16-bit I/O port specified by Port with the value specified by Value\r
117 and returns Value. This function must guarantee that all I/O read and write\r
118 operations are serialized.\r
119\r
120 If 16-bit I/O port operations are not supported, then ASSERT().\r
2281e7a9 121 If Port is not aligned on a 16-bit boundary, then ASSERT().\r
9095d37b 122\r
d074a8e1 123 @param Port The I/O port to write.\r
124 @param Value The value to write to the I/O port.\r
125\r
2281e7a9 126 @return The value written the I/O port.\r
d074a8e1 127\r
128**/\r
129UINT16\r
130EFIAPI\r
131IoWrite16 (\r
132 IN UINTN Port,\r
133 IN UINT16 Value\r
134 )\r
135{\r
136 ASSERT ((Port & 1) == 0);\r
137\r
138 __asm {\r
139 mov ax, word ptr [Value]\r
140 mov dx, word ptr [Port]\r
141 out dx, ax\r
142 }\r
143\r
d074a8e1 144 return Value;\r
145}\r
146\r
147/**\r
148 Reads a 32-bit I/O port.\r
149\r
150 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r
151 This function must guarantee that all I/O read and write operations are\r
152 serialized.\r
153\r
154 If 32-bit I/O port operations are not supported, then ASSERT().\r
2281e7a9 155 If Port is not aligned on a 32-bit boundary, then ASSERT().\r
9095d37b 156\r
d074a8e1 157 @param Port The I/O port to read.\r
158\r
2281e7a9 159 @return The value read.\r
d074a8e1 160\r
161**/\r
162UINT32\r
163EFIAPI\r
164IoRead32 (\r
165 IN UINTN Port\r
166 )\r
167{\r
168 UINT32 Data;\r
169\r
170 ASSERT ((Port & 3) == 0);\r
171\r
172 __asm {\r
173 mov dx, word ptr [Port]\r
174 in eax, dx\r
175 mov dword ptr [Data], eax\r
176 }\r
9095d37b 177\r
d074a8e1 178 return Data;\r
179}\r
180\r
181/**\r
182 Writes a 32-bit I/O port.\r
183\r
184 Writes the 32-bit I/O port specified by Port with the value specified by Value\r
185 and returns Value. This function must guarantee that all I/O read and write\r
186 operations are serialized.\r
187\r
188 If 32-bit I/O port operations are not supported, then ASSERT().\r
2281e7a9 189 If Port is not aligned on a 32-bit boundary, then ASSERT().\r
9095d37b 190\r
d074a8e1 191 @param Port The I/O port to write.\r
192 @param Value The value to write to the I/O port.\r
193\r
2281e7a9 194 @return The value written the I/O port.\r
d074a8e1 195\r
196**/\r
197UINT32\r
198EFIAPI\r
199IoWrite32 (\r
2281e7a9 200 IN UINTN Port,\r
201 IN UINT32 Value\r
d074a8e1 202 )\r
203{\r
204 ASSERT ((Port & 3) == 0);\r
9095d37b 205\r
d074a8e1 206 __asm {\r
207 mov eax, dword ptr [Value]\r
208 mov dx, word ptr [Port]\r
209 out dx, eax\r
210 }\r
211\r
212 return Value;\r
213}\r
214\r