]>
Commit | Line | Data |
---|---|---|
3673b8bf | 1 | /** @file\r |
2 | Common I/O Library routines.\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation<BR>\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | Module Name: IoLibIpf.c\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #define BIT63 0x8000000000000000ULL\r | |
18 | \r | |
19 | #define MAP_PORT_BASE_TO_MEM(_Port) \\r | |
20 | ((((_Port) & 0xfffc) << 10) | ((_Port) & 0x0fff))\r | |
21 | \r | |
22 | /**\r | |
23 | Reads a 8-bit I/O port.\r | |
24 | \r | |
25 | Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r | |
26 | This function must guarantee that all I/O read and write operations are\r | |
27 | serialized.\r | |
28 | \r | |
29 | @param Port The I/O port to read.\r | |
30 | \r | |
31 | @return The value read.\r | |
32 | \r | |
33 | **/\r | |
34 | UINT8\r | |
35 | EFIAPI\r | |
36 | IoRead8 (\r | |
37 | IN UINT64 Port\r | |
38 | )\r | |
39 | {\r | |
40 | UINT64 Address;\r | |
41 | \r | |
42 | //\r | |
43 | // Add the 64MB aligned IO Port space to the IO address\r | |
44 | //\r | |
45 | Address = MAP_PORT_BASE_TO_MEM (Port);\r | |
46 | Address += PcdGet64(PcdIoBlockBaseAddressForIpf);\r | |
47 | \r | |
48 | return MmioRead8 (Address);\r | |
49 | }\r | |
50 | \r | |
51 | /**\r | |
52 | Reads a 16-bit I/O port.\r | |
53 | \r | |
54 | Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r | |
55 | This function must guarantee that all I/O read and write operations are\r | |
56 | serialized.\r | |
57 | \r | |
58 | @param Port The I/O port to read.\r | |
59 | \r | |
60 | @return The value read.\r | |
61 | \r | |
62 | **/\r | |
63 | UINT16\r | |
64 | EFIAPI\r | |
65 | IoRead16 (\r | |
66 | IN UINT64 Port\r | |
67 | )\r | |
68 | {\r | |
69 | UINT64 Address;\r | |
70 | \r | |
71 | //\r | |
72 | // Add the 64MB aligned IO Port space to the IO address\r | |
73 | //\r | |
74 | Address = MAP_PORT_BASE_TO_MEM (Port);\r | |
75 | Address += PcdGet64(PcdIoBlockBaseAddressForIpf);\r | |
76 | \r | |
77 | return MmioRead16 (Address);\r | |
78 | }\r | |
79 | \r | |
80 | /**\r | |
81 | Reads a 32-bit I/O port.\r | |
82 | \r | |
83 | Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r | |
84 | This function must guarantee that all I/O read and write operations are\r | |
85 | serialized.\r | |
86 | \r | |
87 | @param Port The I/O port to read.\r | |
88 | \r | |
89 | @return The value read.\r | |
90 | \r | |
91 | **/\r | |
92 | UINT32\r | |
93 | EFIAPI\r | |
94 | IoRead32 (\r | |
95 | IN UINT64 Port\r | |
96 | )\r | |
97 | {\r | |
98 | UINT64 Address;\r | |
99 | \r | |
100 | //\r | |
101 | // Add the 64MB aligned IO Port space to the IO address\r | |
102 | //\r | |
103 | Address = MAP_PORT_BASE_TO_MEM (Port);\r | |
104 | Address += PcdGet64(PcdIoBlockBaseAddressForIpf);\r | |
105 | \r | |
106 | return MmioRead32 (Address);\r | |
107 | }\r | |
108 | \r | |
9cbd688b | 109 | /**\r |
110 | Reads a 64-bit I/O port.\r | |
111 | \r | |
112 | Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.\r | |
113 | This function must guarantee that all I/O read and write operations are\r | |
114 | serialized.\r | |
115 | \r | |
116 | If 64-bit I/O port operations are not supported, then ASSERT().\r | |
117 | \r | |
118 | @param Port The I/O port to read.\r | |
119 | \r | |
120 | @return The value read.\r | |
121 | \r | |
122 | **/\r | |
123 | UINT64\r | |
124 | EFIAPI\r | |
125 | IoRead64 (\r | |
126 | IN UINTN Port\r | |
127 | )\r | |
128 | {\r | |
129 | ASSERT (FALSE);\r | |
130 | return 0;\r | |
131 | }\r | |
132 | \r | |
3673b8bf | 133 | /**\r |
134 | Writes a 8-bit I/O port.\r | |
135 | \r | |
136 | Writes the 8-bit I/O port specified by Port with the value specified by Value\r | |
137 | and returns Value. This function must guarantee that all I/O read and write\r | |
138 | operations are serialized.\r | |
139 | \r | |
140 | @param Port The I/O port to write.\r | |
141 | @param Value The value to write to the I/O port.\r | |
142 | \r | |
143 | @return The value written the I/O port.\r | |
144 | \r | |
145 | **/\r | |
146 | UINT8\r | |
147 | EFIAPI\r | |
148 | IoWrite8 (\r | |
149 | IN UINT64 Port,\r | |
150 | IN UINT8 Data\r | |
151 | )\r | |
152 | {\r | |
153 | UINT64 Address;\r | |
154 | \r | |
155 | //\r | |
156 | // Add the 64MB aligned IO Port space to the IO address\r | |
157 | //\r | |
158 | Address = MAP_PORT_BASE_TO_MEM (Port);\r | |
159 | Address += PcdGet64(PcdIoBlockBaseAddressForIpf);\r | |
160 | \r | |
161 | return MmioWrite8 (Address, Data);\r | |
162 | }\r | |
163 | \r | |
164 | /**\r | |
165 | Writes a 16-bit I/O port.\r | |
166 | \r | |
167 | Writes the 16-bit I/O port specified by Port with the value specified by Value\r | |
168 | and returns Value. This function must guarantee that all I/O read and write\r | |
169 | operations are serialized.\r | |
170 | \r | |
171 | @param Port The I/O port to write.\r | |
172 | @param Value The value to write to the I/O port.\r | |
173 | \r | |
174 | @return The value written the I/O port.\r | |
175 | \r | |
176 | **/\r | |
177 | UINT16\r | |
178 | EFIAPI\r | |
179 | IoWrite16 (\r | |
180 | IN UINT64 Port,\r | |
181 | IN UINT16 Data\r | |
182 | )\r | |
183 | {\r | |
184 | UINT64 Address;\r | |
185 | \r | |
186 | //\r | |
187 | // Add the 64MB aligned IO Port space to the IO address\r | |
188 | //\r | |
189 | Address = MAP_PORT_BASE_TO_MEM (Port);\r | |
190 | Address += PcdGet64(PcdIoBlockBaseAddressForIpf);\r | |
191 | \r | |
192 | return MmioWrite16 (Address, Data);\r | |
193 | }\r | |
194 | \r | |
195 | /**\r | |
196 | Writes a 32-bit I/O port.\r | |
197 | \r | |
198 | Writes the 32-bit I/O port specified by Port with the value specified by Value\r | |
199 | and returns Value. This function must guarantee that all I/O read and write\r | |
200 | operations are serialized.\r | |
201 | \r | |
202 | @param Port The I/O port to write.\r | |
203 | @param Value The value to write to the I/O port.\r | |
204 | \r | |
205 | @return The value written the I/O port.\r | |
206 | \r | |
207 | **/\r | |
208 | UINT32\r | |
209 | EFIAPI\r | |
210 | IoWrite32 (\r | |
211 | IN UINT64 Port,\r | |
212 | IN UINT32 Data\r | |
213 | )\r | |
214 | {\r | |
215 | UINT64 Address;\r | |
216 | \r | |
217 | //\r | |
218 | // Add the 64MB aligned IO Port space to the IO address\r | |
219 | //\r | |
220 | Address = MAP_PORT_BASE_TO_MEM (Port);\r | |
221 | Address += PcdGet64(PcdIoBlockBaseAddressForIpf);\r | |
222 | \r | |
223 | return MmioWrite32 (Address, Data);\r | |
224 | }\r | |
225 | \r | |
9cbd688b | 226 | /**\r |
227 | Writes a 64-bit I/O port.\r | |
228 | \r | |
229 | Writes the 64-bit I/O port specified by Port with the value specified by Value\r | |
230 | and returns Value. This function must guarantee that all I/O read and write\r | |
231 | operations are serialized.\r | |
232 | \r | |
233 | If 64-bit I/O port operations are not supported, then ASSERT().\r | |
234 | \r | |
235 | @param Port The I/O port to write.\r | |
236 | @param Value The value to write to the I/O port.\r | |
237 | \r | |
238 | @return The value written the I/O port.\r | |
239 | \r | |
240 | **/\r | |
241 | UINT64\r | |
242 | EFIAPI\r | |
243 | IoWrite64 (\r | |
244 | IN UINTN Port,\r | |
245 | IN UINT64 Value\r | |
246 | )\r | |
247 | {\r | |
248 | ASSERT (FALSE);\r | |
249 | return 0;\r | |
250 | }\r | |
251 | \r | |
3673b8bf | 252 | /**\r |
253 | Reads a 8-bit MMIO register.\r | |
254 | \r | |
255 | Reads the 8-bit MMIO register specified by Address. The 8-bit read value is\r | |
256 | returned. This function must guarantee that all MMIO read and write\r | |
257 | operations are serialized.\r | |
258 | \r | |
259 | @param Address The MMIO register to read.\r | |
260 | \r | |
261 | @return The value read.\r | |
262 | \r | |
263 | **/\r | |
264 | UINT8\r | |
265 | EFIAPI\r | |
266 | MmioRead8 (\r | |
267 | IN UINT64 Address\r | |
268 | )\r | |
269 | {\r | |
270 | UINT8 Data;\r | |
271 | \r | |
272 | Address |= BIT63;\r | |
273 | \r | |
274 | MemoryFence ();\r | |
275 | Data = *((volatile UINT8 *) Address);\r | |
276 | MemoryFence ();\r | |
277 | \r | |
278 | return Data;\r | |
279 | }\r | |
280 | \r | |
281 | /**\r | |
282 | Reads a 16-bit MMIO register.\r | |
283 | \r | |
284 | Reads the 16-bit MMIO register specified by Address. The 16-bit read value is\r | |
285 | returned. This function must guarantee that all MMIO read and write\r | |
286 | operations are serialized.\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 UINT64 Address\r | |
297 | )\r | |
298 | {\r | |
299 | UINT16 Data;\r | |
300 | \r | |
301 | Address |= BIT63;\r | |
302 | \r | |
303 | MemoryFence ();\r | |
304 | Data = *((volatile UINT16 *) Address);\r | |
305 | MemoryFence ();\r | |
306 | \r | |
307 | return Data;\r | |
308 | }\r | |
309 | \r | |
310 | /**\r | |
311 | Reads a 32-bit MMIO register.\r | |
312 | \r | |
313 | Reads the 32-bit MMIO register specified by Address. The 32-bit read value is\r | |
314 | returned. This function must guarantee that all MMIO read and write\r | |
315 | operations are serialized.\r | |
316 | \r | |
317 | @param Address The MMIO register to read.\r | |
318 | \r | |
319 | @return The value read.\r | |
320 | \r | |
321 | **/\r | |
322 | UINT32\r | |
323 | EFIAPI\r | |
324 | MmioRead32 (\r | |
325 | IN UINT64 Address\r | |
326 | )\r | |
327 | {\r | |
328 | UINT32 Data;\r | |
329 | \r | |
330 | Address |= BIT63;\r | |
331 | \r | |
332 | MemoryFence ();\r | |
333 | Data = *((volatile UINT32 *) Address);\r | |
334 | MemoryFence ();\r | |
335 | \r | |
336 | return Data;\r | |
337 | }\r | |
338 | \r | |
339 | /**\r | |
340 | Reads a 64-bit MMIO register.\r | |
341 | \r | |
342 | Reads the 64-bit MMIO register specified by Address. The 64-bit read value is\r | |
343 | returned. This function must guarantee that all MMIO read and write\r | |
344 | operations are serialized.\r | |
345 | \r | |
346 | @param Address The MMIO register to read.\r | |
347 | \r | |
348 | @return The value read.\r | |
349 | \r | |
350 | **/\r | |
351 | UINT64\r | |
352 | EFIAPI\r | |
353 | MmioRead64 (\r | |
354 | IN UINT64 Address\r | |
355 | )\r | |
356 | {\r | |
357 | UINT64 Data;\r | |
358 | \r | |
359 | Address |= BIT63;\r | |
360 | \r | |
361 | MemoryFence ();\r | |
362 | Data = *((volatile UINT64 *) Address);\r | |
363 | MemoryFence ();\r | |
364 | \r | |
365 | return Data;\r | |
366 | \r | |
367 | }\r | |
368 | \r | |
369 | /**\r | |
370 | Writes a 8-bit MMIO register.\r | |
371 | \r | |
372 | Writes the 8-bit MMIO register specified by Address with the value specified\r | |
373 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
374 | and write operations are serialized.\r | |
375 | \r | |
376 | @param Address The MMIO register to write.\r | |
377 | @param Data The value to write to the MMIO register.\r | |
378 | \r | |
379 | @return The value written the memory address.\r | |
380 | \r | |
381 | **/\r | |
382 | UINT8\r | |
383 | EFIAPI\r | |
384 | MmioWrite8 (\r | |
385 | IN UINT64 Address,\r | |
386 | IN UINT8 Data\r | |
387 | )\r | |
388 | {\r | |
389 | Address |= BIT63;\r | |
390 | \r | |
391 | MemoryFence ();\r | |
392 | *((volatile UINT8 *) Address) = Data;\r | |
393 | MemoryFence ();\r | |
394 | \r | |
395 | return Data;\r | |
396 | }\r | |
397 | \r | |
398 | /**\r | |
399 | Writes a 16-bit MMIO register.\r | |
400 | \r | |
401 | Writes the 16-bit MMIO register specified by Address with the value specified\r | |
402 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
403 | and write operations are serialized.\r | |
404 | \r | |
405 | @param Address The MMIO register to write.\r | |
406 | @param Data The value to write to the MMIO register.\r | |
407 | \r | |
408 | @return The value written the memory address.\r | |
409 | \r | |
410 | **/\r | |
411 | UINT16\r | |
412 | EFIAPI\r | |
413 | MmioWrite16 (\r | |
414 | IN UINT64 Address,\r | |
415 | IN UINT16 Data\r | |
416 | )\r | |
417 | {\r | |
418 | Address |= BIT63;\r | |
419 | \r | |
420 | MemoryFence ();\r | |
421 | *((volatile UINT16 *) Address) = Data;\r | |
422 | MemoryFence ();\r | |
423 | \r | |
424 | return Data;\r | |
425 | }\r | |
426 | \r | |
427 | /**\r | |
428 | Writes a 32-bit MMIO register.\r | |
429 | \r | |
430 | Writes the 32-bit MMIO register specified by Address with the value specified\r | |
431 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
432 | and write operations are serialized.\r | |
433 | \r | |
434 | @param Address The MMIO register to write.\r | |
435 | @param Data The value to write to the MMIO register.\r | |
436 | \r | |
437 | @return The value written the memory address.\r | |
438 | \r | |
439 | **/\r | |
440 | UINT32\r | |
441 | EFIAPI\r | |
442 | MmioWrite32 (\r | |
443 | IN UINT64 Address,\r | |
444 | IN UINT32 Data\r | |
445 | )\r | |
446 | {\r | |
447 | Address |= BIT63;\r | |
448 | \r | |
449 | MemoryFence ();\r | |
450 | *((volatile UINT32 *) Address) = Data;\r | |
451 | MemoryFence ();\r | |
452 | \r | |
453 | return Data;\r | |
454 | }\r | |
455 | \r | |
456 | /**\r | |
457 | Writes a 64-bit MMIO register.\r | |
458 | \r | |
459 | Writes the 64-bit MMIO register specified by Address with the value specified\r | |
460 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
461 | and write operations are serialized.\r | |
462 | \r | |
463 | @param Address The MMIO register to write.\r | |
464 | @param Data The value to write to the MMIO register.\r | |
465 | \r | |
466 | @return The value written the memory address.\r | |
467 | \r | |
468 | **/\r | |
469 | UINT64\r | |
470 | EFIAPI\r | |
471 | MmioWrite64 (\r | |
472 | IN UINT64 Address,\r | |
473 | IN UINT64 Data\r | |
474 | )\r | |
475 | {\r | |
476 | Address |= BIT63;\r | |
477 | \r | |
478 | MemoryFence ();\r | |
479 | *((volatile UINT64 *) Address) = Data;\r | |
480 | MemoryFence ();\r | |
481 | \r | |
482 | return Data;\r | |
483 | }\r |