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