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