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