]>
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 | |
5dedabbb | 5 | Copyright (c) 2006 - 2008, Intel Corporation<BR> All rights\r |
d074a8e1 | 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 | |
32 | UINT8\r | |
33 | EFIAPI\r | |
34 | MmioRead8 (\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 | |
58 | UINT8\r | |
59 | EFIAPI\r | |
60 | MmioWrite8 (\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 | |
82 | UINT16\r | |
83 | EFIAPI\r | |
84 | MmioRead16 (\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 | |
109 | UINT16\r | |
110 | EFIAPI\r | |
111 | MmioWrite16 (\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 | |
134 | UINT32\r | |
135 | EFIAPI\r | |
136 | MmioRead32 (\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 | |
161 | UINT32\r | |
162 | EFIAPI\r | |
163 | MmioWrite32 (\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 | |
186 | UINT64\r | |
187 | EFIAPI\r | |
188 | MmioRead64 (\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 |
212 | UINT64\r | |
213 | EFIAPI\r | |
214 | MmioWrite64 (\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 | |
239 | UINT8\r | |
240 | EFIAPI\r | |
241 | IoRead8 (\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 | |
273 | UINT8\r | |
274 | EFIAPI\r | |
275 | IoWrite8 (\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 | |
302 | UINT16\r | |
303 | EFIAPI\r | |
304 | IoRead16 (\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 | |
338 | UINT16\r | |
339 | EFIAPI\r | |
340 | IoWrite16 (\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 | |
d074a8e1 | 353 | return Value;\r |
354 | }\r | |
355 | \r | |
356 | /**\r | |
357 | Reads a 32-bit I/O port.\r | |
358 | \r | |
359 | Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r | |
360 | This function must guarantee that all I/O read and write operations are\r | |
361 | serialized.\r | |
362 | \r | |
363 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
364 | \r | |
365 | @param Port The I/O port to read.\r | |
366 | \r | |
38bbd3d9 | 367 | @return The value read from Port.\r |
d074a8e1 | 368 | \r |
369 | **/\r | |
370 | UINT32\r | |
371 | EFIAPI\r | |
372 | IoRead32 (\r | |
373 | IN UINTN Port\r | |
374 | )\r | |
375 | {\r | |
376 | UINT32 Data;\r | |
377 | \r | |
378 | ASSERT ((Port & 3) == 0);\r | |
379 | \r | |
380 | __asm {\r | |
381 | mov dx, word ptr [Port]\r | |
382 | in eax, dx\r | |
383 | mov dword ptr [Data], eax\r | |
384 | }\r | |
385 | \r | |
386 | return Data;\r | |
387 | }\r | |
388 | \r | |
389 | /**\r | |
390 | Writes a 32-bit I/O port.\r | |
391 | \r | |
392 | Writes the 32-bit I/O port specified by Port with the value specified by Value\r | |
393 | and returns Value. This function must guarantee that all I/O read and write\r | |
394 | operations are serialized.\r | |
395 | \r | |
396 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
397 | \r | |
398 | @param Port The I/O port to write.\r | |
399 | @param Value The value to write to the I/O port.\r | |
400 | \r | |
38bbd3d9 | 401 | @return The value written to the I/O port. It equals to the input\r |
402 | Value instead of the actual value read back from the\r | |
403 | I/O port.\r | |
d074a8e1 | 404 | \r |
405 | **/\r | |
406 | UINT32\r | |
407 | EFIAPI\r | |
408 | IoWrite32 (\r | |
409 | IN UINTN Port,\r | |
410 | IN UINT32 Value\r | |
411 | )\r | |
412 | {\r | |
413 | ASSERT ((Port & 3) == 0);\r | |
414 | \r | |
415 | __asm {\r | |
416 | mov eax, dword ptr [Value]\r | |
417 | mov dx, word ptr [Port]\r | |
418 | out dx, eax\r | |
419 | }\r | |
420 | \r | |
421 | return Value;\r | |
422 | }\r | |
423 | \r |