]>
Commit | Line | Data |
---|---|---|
e1f414b6 | 1 | /** @file\r |
2 | I/O Library. This file has compiler specifics for Microsft C as there is no\r | |
3 | ANSI C standard for doing IO.\r | |
4 | \r | |
5 | MSC - uses intrinsic functions and the optimize will remove the function call\r | |
6 | overhead.\r | |
7 | \r | |
8 | We don't advocate putting compiler specifics in libraries or drivers but there\r | |
9 | is no other way to make this work.\r | |
10 | \r | |
11 | Copyright (c) 2006 - 2007, Intel Corporation<BR>\r | |
12 | All rights reserved. This program and the accompanying materials\r | |
13 | are licensed and made available under the terms and conditions of the BSD License\r | |
14 | which accompanies this distribution. The full text of the license may be found at\r | |
15 | http://opensource.org/licenses/bsd-license.php\r | |
16 | \r | |
17 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
18 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
19 | \r | |
e1f414b6 | 20 | **/\r |
21 | \r | |
22 | \r | |
23 | //\r | |
24 | // Include common header file for this module.\r | |
25 | //\r | |
f734a10a | 26 | #include "BaseIoLibIntrinsicInternal.h"\r |
e1f414b6 | 27 | \r |
28 | //\r | |
29 | // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics\r | |
30 | //\r | |
31 | int _inp (unsigned short port);\r | |
32 | unsigned short _inpw (unsigned short port);\r | |
33 | unsigned long _inpd (unsigned short port);\r | |
34 | int _outp (unsigned short port, int databyte );\r | |
35 | unsigned short _outpw (unsigned short port, unsigned short dataword );\r | |
36 | unsigned long _outpd (unsigned short port, unsigned long dataword );\r | |
37 | void _ReadWriteBarrier (void);\r | |
38 | \r | |
39 | #pragma intrinsic(_inp)\r | |
40 | #pragma intrinsic(_inpw)\r | |
41 | #pragma intrinsic(_inpd)\r | |
42 | #pragma intrinsic(_outp)\r | |
43 | #pragma intrinsic(_outpw)\r | |
44 | #pragma intrinsic(_outpd)\r | |
45 | #pragma intrinsic(_ReadWriteBarrier)\r | |
46 | \r | |
47 | //\r | |
48 | // _ReadWriteBarrier() forces memory reads and writes to complete at the point\r | |
49 | // in the call. This is only a hint to the compiler and does emit code.\r | |
50 | // In past versions of the compiler, _ReadWriteBarrier was enforced only\r | |
51 | // locally and did not affect functions up the call tree. In Visual C++\r | |
52 | // 2005, _ReadWriteBarrier is enforced all the way up the call tree.\r | |
53 | //\r | |
54 | \r | |
55 | /**\r | |
56 | Reads an 8-bit I/O port.\r | |
57 | \r | |
58 | Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r | |
59 | This function must guarantee that all I/O read and write operations are\r | |
60 | serialized.\r | |
61 | \r | |
62 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
63 | \r | |
64 | @param Port The I/O port to read.\r | |
65 | \r | |
66 | @return The value read.\r | |
67 | \r | |
68 | **/\r | |
69 | UINT8\r | |
70 | EFIAPI\r | |
71 | IoRead8 (\r | |
72 | IN UINTN Port\r | |
73 | )\r | |
74 | {\r | |
75 | UINT8 Value;\r | |
76 | \r | |
77 | _ReadWriteBarrier ();\r | |
78 | Value = (UINT8)_inp ((UINT16)Port);\r | |
79 | _ReadWriteBarrier ();\r | |
80 | return Value;\r | |
81 | }\r | |
82 | \r | |
83 | /**\r | |
84 | Writes an 8-bit I/O port.\r | |
85 | \r | |
86 | Writes the 8-bit I/O port specified by Port with the value specified by Value\r | |
87 | and returns Value. This function must guarantee that all I/O read and write\r | |
88 | operations are serialized.\r | |
89 | \r | |
90 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
91 | \r | |
92 | @param Port The I/O port to write.\r | |
93 | @param Value The value to write to the I/O port.\r | |
94 | \r | |
95 | @return The value written the I/O port.\r | |
96 | \r | |
97 | **/\r | |
98 | UINT8\r | |
99 | EFIAPI\r | |
100 | IoWrite8 (\r | |
101 | IN UINTN Port,\r | |
102 | IN UINT8 Value\r | |
103 | )\r | |
104 | {\r | |
105 | _ReadWriteBarrier ();\r | |
106 | (UINT8)_outp ((UINT16)Port, Value);\r | |
107 | _ReadWriteBarrier ();\r | |
108 | return Value;\r | |
109 | }\r | |
110 | \r | |
111 | /**\r | |
112 | Reads a 16-bit I/O port.\r | |
113 | \r | |
114 | Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r | |
115 | This function must guarantee that all I/O read and write operations are\r | |
116 | serialized.\r | |
117 | \r | |
118 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
119 | \r | |
120 | @param Port The I/O port to read.\r | |
121 | \r | |
122 | @return The value read.\r | |
123 | \r | |
124 | **/\r | |
125 | UINT16\r | |
126 | EFIAPI\r | |
127 | IoRead16 (\r | |
128 | IN UINTN Port\r | |
129 | )\r | |
130 | {\r | |
131 | UINT16 Value;\r | |
132 | \r | |
133 | ASSERT ((Port & 1) == 0);\r | |
134 | _ReadWriteBarrier ();\r | |
135 | Value = _inpw ((UINT16)Port);\r | |
136 | _ReadWriteBarrier ();\r | |
137 | return Value;\r | |
138 | }\r | |
139 | \r | |
140 | /**\r | |
141 | Writes a 16-bit I/O port.\r | |
142 | \r | |
143 | Writes the 16-bit I/O port specified by Port with the value specified by Value\r | |
144 | and returns Value. This function must guarantee that all I/O read and write\r | |
145 | operations are serialized.\r | |
146 | \r | |
147 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
148 | \r | |
149 | @param Port The I/O port to write.\r | |
150 | @param Value The value to write to the I/O port.\r | |
151 | \r | |
152 | @return The value written the I/O port.\r | |
153 | \r | |
154 | **/\r | |
155 | UINT16\r | |
156 | EFIAPI\r | |
157 | IoWrite16 (\r | |
158 | IN UINTN Port,\r | |
159 | IN UINT16 Value\r | |
160 | )\r | |
161 | {\r | |
162 | ASSERT ((Port & 1) == 0);\r | |
163 | _ReadWriteBarrier ();\r | |
164 | _outpw ((UINT16)Port, Value);\r | |
165 | _ReadWriteBarrier ();\r | |
166 | return Value;\r | |
167 | }\r | |
168 | \r | |
169 | /**\r | |
170 | Reads a 32-bit I/O port.\r | |
171 | \r | |
172 | Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r | |
173 | This function must guarantee that all I/O read and write operations are\r | |
174 | serialized.\r | |
175 | \r | |
176 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
177 | \r | |
178 | @param Port The I/O port to read.\r | |
179 | \r | |
180 | @return The value read.\r | |
181 | \r | |
182 | **/\r | |
183 | UINT32\r | |
184 | EFIAPI\r | |
185 | IoRead32 (\r | |
186 | IN UINTN Port\r | |
187 | )\r | |
188 | {\r | |
189 | UINT32 Value;\r | |
190 | \r | |
191 | ASSERT ((Port & 3) == 0);\r | |
192 | _ReadWriteBarrier ();\r | |
193 | Value = _inpd ((UINT16)Port);\r | |
194 | _ReadWriteBarrier ();\r | |
195 | return Value;\r | |
196 | }\r | |
197 | \r | |
198 | /**\r | |
199 | Writes a 32-bit I/O port.\r | |
200 | \r | |
201 | Writes the 32-bit I/O port specified by Port with the value specified by Value\r | |
202 | and returns Value. This function must guarantee that all I/O read and write\r | |
203 | operations are serialized.\r | |
204 | \r | |
205 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
206 | \r | |
207 | @param Port The I/O port to write.\r | |
208 | @param Value The value to write to the I/O port.\r | |
209 | \r | |
210 | @return The value written the I/O port.\r | |
211 | \r | |
212 | **/\r | |
213 | UINT32\r | |
214 | EFIAPI\r | |
215 | IoWrite32 (\r | |
216 | IN UINTN Port,\r | |
217 | IN UINT32 Value\r | |
218 | )\r | |
219 | {\r | |
220 | ASSERT ((Port & 3) == 0);\r | |
221 | _ReadWriteBarrier ();\r | |
222 | _outpd ((UINT16)Port, Value);\r | |
223 | _ReadWriteBarrier ();\r | |
224 | return Value;\r | |
225 | }\r | |
226 | \r | |
227 | \r | |
228 | /**\r | |
229 | Reads an 8-bit MMIO register.\r | |
230 | \r | |
231 | Reads the 8-bit MMIO register specified by Address. The 8-bit read value is\r | |
232 | returned. This function must guarantee that all MMIO read and write\r | |
233 | operations are serialized.\r | |
234 | \r | |
235 | If 8-bit MMIO register operations are not supported, then ASSERT().\r | |
236 | \r | |
237 | @param Address The MMIO register to read.\r | |
238 | \r | |
239 | @return The value read.\r | |
240 | \r | |
241 | **/\r | |
242 | UINT8\r | |
243 | EFIAPI\r | |
244 | MmioRead8 (\r | |
245 | IN UINTN Address\r | |
246 | )\r | |
247 | {\r | |
248 | UINT8 Value;\r | |
249 | \r | |
250 | Value = *(volatile UINT8*)Address;\r | |
251 | return Value;\r | |
252 | }\r | |
253 | \r | |
254 | /**\r | |
255 | Writes an 8-bit MMIO register.\r | |
256 | \r | |
257 | Writes the 8-bit MMIO register specified by Address with the value specified\r | |
258 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
259 | and write operations are serialized.\r | |
260 | \r | |
261 | If 8-bit MMIO register operations are not supported, then ASSERT().\r | |
262 | \r | |
263 | @param Address The MMIO register to write.\r | |
264 | @param Value The value to write to the MMIO register.\r | |
265 | \r | |
266 | **/\r | |
267 | UINT8\r | |
268 | EFIAPI\r | |
269 | MmioWrite8 (\r | |
270 | IN UINTN Address,\r | |
271 | IN UINT8 Value\r | |
272 | )\r | |
273 | {\r | |
274 | return *(volatile UINT8*)Address = Value;\r | |
275 | }\r | |
276 | \r | |
277 | /**\r | |
278 | Reads a 16-bit MMIO register.\r | |
279 | \r | |
280 | Reads the 16-bit MMIO register specified by Address. The 16-bit read value is\r | |
281 | returned. This function must guarantee that all MMIO read and write\r | |
282 | operations are serialized.\r | |
283 | \r | |
284 | If 16-bit MMIO register operations are not supported, then ASSERT().\r | |
285 | \r | |
286 | @param Address The MMIO register to read.\r | |
287 | \r | |
288 | @return The value read.\r | |
289 | \r | |
290 | **/\r | |
291 | UINT16\r | |
292 | EFIAPI\r | |
293 | MmioRead16 (\r | |
294 | IN UINTN Address\r | |
295 | )\r | |
296 | {\r | |
297 | UINT16 Value;\r | |
298 | \r | |
299 | ASSERT ((Address & 1) == 0);\r | |
300 | Value = *(volatile UINT16*)Address;\r | |
301 | return Value;\r | |
302 | }\r | |
303 | \r | |
304 | /**\r | |
305 | Writes a 16-bit MMIO register.\r | |
306 | \r | |
307 | Writes the 16-bit MMIO register specified by Address with the value specified\r | |
308 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
309 | and write operations are serialized.\r | |
310 | \r | |
311 | If 16-bit MMIO register operations are not supported, then ASSERT().\r | |
312 | \r | |
313 | @param Address The MMIO register to write.\r | |
314 | @param Value The value to write to the MMIO register.\r | |
315 | \r | |
316 | **/\r | |
317 | UINT16\r | |
318 | EFIAPI\r | |
319 | MmioWrite16 (\r | |
320 | IN UINTN Address,\r | |
321 | IN UINT16 Value\r | |
322 | )\r | |
323 | {\r | |
324 | ASSERT ((Address & 1) == 0);\r | |
325 | return *(volatile UINT16*)Address = Value;\r | |
326 | }\r | |
327 | \r | |
328 | /**\r | |
329 | Reads a 32-bit MMIO register.\r | |
330 | \r | |
331 | Reads the 32-bit MMIO register specified by Address. The 32-bit read value is\r | |
332 | returned. This function must guarantee that all MMIO read and write\r | |
333 | operations are serialized.\r | |
334 | \r | |
335 | If 32-bit MMIO register operations are not supported, then ASSERT().\r | |
336 | \r | |
337 | @param Address The MMIO register to read.\r | |
338 | \r | |
339 | @return The value read.\r | |
340 | \r | |
341 | **/\r | |
342 | UINT32\r | |
343 | EFIAPI\r | |
344 | MmioRead32 (\r | |
345 | IN UINTN Address\r | |
346 | )\r | |
347 | {\r | |
348 | UINT32 Value;\r | |
349 | \r | |
350 | ASSERT ((Address & 3) == 0);\r | |
351 | Value = *(volatile UINT32*)Address;\r | |
352 | return Value;\r | |
353 | }\r | |
354 | \r | |
355 | /**\r | |
356 | Writes a 32-bit MMIO register.\r | |
357 | \r | |
358 | Writes the 32-bit MMIO register specified by Address with the value specified\r | |
359 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
360 | and write operations are serialized.\r | |
361 | \r | |
362 | If 32-bit MMIO register operations are not supported, then ASSERT().\r | |
363 | \r | |
364 | @param Address The MMIO register to write.\r | |
365 | @param Value The value to write to the MMIO register.\r | |
366 | \r | |
367 | **/\r | |
368 | UINT32\r | |
369 | EFIAPI\r | |
370 | MmioWrite32 (\r | |
371 | IN UINTN Address,\r | |
372 | IN UINT32 Value\r | |
373 | )\r | |
374 | {\r | |
375 | ASSERT ((Address & 3) == 0);\r | |
376 | return *(volatile UINT32*)Address = Value;\r | |
377 | }\r | |
378 | \r | |
379 | /**\r | |
380 | Reads a 64-bit MMIO register.\r | |
381 | \r | |
382 | Reads the 64-bit MMIO register specified by Address. The 64-bit read value is\r | |
383 | returned. This function must guarantee that all MMIO read and write\r | |
384 | operations are serialized.\r | |
385 | \r | |
386 | If 64-bit MMIO register operations are not supported, then ASSERT().\r | |
387 | \r | |
388 | @param Address The MMIO register to read.\r | |
389 | \r | |
390 | @return The value read.\r | |
391 | \r | |
392 | **/\r | |
393 | UINT64\r | |
394 | EFIAPI\r | |
395 | MmioRead64 (\r | |
396 | IN UINTN Address\r | |
397 | )\r | |
398 | {\r | |
399 | UINT64 Value;\r | |
400 | \r | |
401 | ASSERT ((Address & 7) == 0);\r | |
402 | Value = *(volatile UINT64*)Address;\r | |
403 | return Value;\r | |
404 | }\r | |
405 | \r | |
406 | /**\r | |
407 | Writes a 64-bit MMIO register.\r | |
408 | \r | |
409 | Writes the 64-bit MMIO register specified by Address with the value specified\r | |
410 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
411 | and write operations are serialized.\r | |
412 | \r | |
413 | If 64-bit MMIO register operations are not supported, then ASSERT().\r | |
414 | \r | |
415 | @param Address The MMIO register to write.\r | |
416 | @param Value The value to write to the MMIO register.\r | |
417 | \r | |
418 | **/\r | |
419 | UINT64\r | |
420 | EFIAPI\r | |
421 | MmioWrite64 (\r | |
422 | IN UINTN Address,\r | |
423 | IN UINT64 Value\r | |
424 | )\r | |
425 | {\r | |
426 | ASSERT ((Address & 7) == 0);\r | |
427 | return *(volatile UINT64*)Address = Value;\r | |
428 | }\r | |
429 | \r |