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