]>
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 | |
9095d37b | 13 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9344f092 | 14 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
e1f414b6 | 15 | \r |
e1f414b6 | 16 | **/\r |
17 | \r | |
1efcc4ae | 18 | \r |
f734a10a | 19 | #include "BaseIoLibIntrinsicInternal.h"\r |
e1f414b6 | 20 | \r |
2281e7a9 | 21 | /**\r |
22 | Reads an 8-bit I/O port.\r | |
23 | \r | |
24 | Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r | |
25 | This function must guarantee that all I/O read and write operations are\r | |
26 | serialized.\r | |
27 | \r | |
28 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
29 | \r | |
30 | @param Port The I/O port to read.\r | |
31 | \r | |
32 | @return The value read.\r | |
33 | \r | |
34 | **/\r | |
9de780dc | 35 | __inline__\r |
e1f414b6 | 36 | UINT8\r |
37 | EFIAPI\r | |
38 | IoRead8 (\r | |
39 | IN UINTN Port\r | |
40 | )\r | |
41 | {\r | |
42 | UINT8 Data;\r | |
43 | \r | |
44 | __asm__ __volatile__ ("inb %w1,%b0" : "=a" (Data) : "d" ((UINT16)Port));\r | |
45 | return Data;\r | |
46 | }\r | |
47 | \r | |
2281e7a9 | 48 | /**\r |
49 | Writes an 8-bit I/O port.\r | |
50 | \r | |
51 | Writes the 8-bit I/O port specified by Port with the value specified by Value\r | |
52 | and returns Value. This function must guarantee that all I/O read and write\r | |
53 | operations are serialized.\r | |
54 | \r | |
55 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
56 | \r | |
57 | @param Port The I/O port to write.\r | |
58 | @param Value The value to write to the I/O port.\r | |
59 | \r | |
60 | @return The value written the I/O port.\r | |
61 | \r | |
62 | **/\r | |
9de780dc | 63 | __inline__\r |
e1f414b6 | 64 | UINT8\r |
65 | EFIAPI\r | |
66 | IoWrite8 (\r | |
67 | IN UINTN Port,\r | |
68 | IN UINT8 Value\r | |
69 | )\r | |
70 | {\r | |
71 | __asm__ __volatile__ ("outb %b0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r | |
72 | return Value;;\r | |
73 | }\r | |
74 | \r | |
2281e7a9 | 75 | /**\r |
76 | Reads a 16-bit I/O port.\r | |
77 | \r | |
78 | Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r | |
79 | This function must guarantee that all I/O read and write operations are\r | |
80 | serialized.\r | |
81 | \r | |
82 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
83 | If Port is not aligned on a 16-bit boundary, then ASSERT().\r | |
84 | \r | |
85 | @param Port The I/O port to read.\r | |
86 | \r | |
87 | @return The value read.\r | |
88 | \r | |
89 | **/\r | |
9de780dc | 90 | __inline__\r |
e1f414b6 | 91 | UINT16\r |
92 | EFIAPI\r | |
93 | IoRead16 (\r | |
94 | IN UINTN Port\r | |
95 | )\r | |
96 | {\r | |
97 | UINT16 Data;\r | |
98 | \r | |
99 | ASSERT ((Port & 1) == 0);\r | |
100 | __asm__ __volatile__ ("inw %w1,%w0" : "=a" (Data) : "d" ((UINT16)Port));\r | |
101 | return Data;\r | |
102 | }\r | |
103 | \r | |
2281e7a9 | 104 | /**\r |
105 | Writes a 16-bit I/O port.\r | |
106 | \r | |
107 | Writes the 16-bit I/O port specified by Port with the value specified by Value\r | |
108 | and returns Value. This function must guarantee that all I/O read and write\r | |
109 | operations are serialized.\r | |
110 | \r | |
111 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
112 | If Port is not aligned on a 16-bit boundary, then ASSERT().\r | |
9095d37b | 113 | \r |
2281e7a9 | 114 | @param Port The I/O port to write.\r |
115 | @param Value The value to write to the I/O port.\r | |
116 | \r | |
117 | @return The value written the I/O port.\r | |
118 | \r | |
119 | **/\r | |
9de780dc | 120 | __inline__\r |
e1f414b6 | 121 | UINT16\r |
122 | EFIAPI\r | |
123 | IoWrite16 (\r | |
124 | IN UINTN Port,\r | |
125 | IN UINT16 Value\r | |
126 | )\r | |
127 | {\r | |
128 | ASSERT ((Port & 1) == 0);\r | |
129 | __asm__ __volatile__ ("outw %w0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r | |
130 | return Value;;\r | |
131 | }\r | |
132 | \r | |
2281e7a9 | 133 | /**\r |
134 | Reads a 32-bit I/O port.\r | |
135 | \r | |
136 | Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r | |
137 | This function must guarantee that all I/O read and write operations are\r | |
138 | serialized.\r | |
139 | \r | |
140 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
141 | If Port is not aligned on a 32-bit boundary, then ASSERT().\r | |
9095d37b | 142 | \r |
2281e7a9 | 143 | @param Port The I/O port to read.\r |
144 | \r | |
145 | @return The value read.\r | |
146 | \r | |
147 | **/\r | |
9de780dc | 148 | __inline__\r |
e1f414b6 | 149 | UINT32\r |
150 | EFIAPI\r | |
151 | IoRead32 (\r | |
152 | IN UINTN Port\r | |
153 | )\r | |
154 | {\r | |
155 | UINT32 Data;\r | |
156 | \r | |
157 | ASSERT ((Port & 3) == 0);\r | |
158 | __asm__ __volatile__ ("inl %w1,%0" : "=a" (Data) : "d" ((UINT16)Port));\r | |
159 | return Data;\r | |
160 | }\r | |
161 | \r | |
2281e7a9 | 162 | /**\r |
163 | Writes a 32-bit I/O port.\r | |
164 | \r | |
165 | Writes the 32-bit I/O port specified by Port with the value specified by Value\r | |
166 | and returns Value. This function must guarantee that all I/O read and write\r | |
167 | operations are serialized.\r | |
168 | \r | |
169 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
170 | If Port is not aligned on a 32-bit boundary, then ASSERT().\r | |
9095d37b | 171 | \r |
2281e7a9 | 172 | @param Port The I/O port to write.\r |
173 | @param Value The value to write to the I/O port.\r | |
174 | \r | |
175 | @return The value written the I/O port.\r | |
176 | \r | |
177 | **/\r | |
9de780dc | 178 | __inline__\r |
e1f414b6 | 179 | UINT32\r |
180 | EFIAPI\r | |
181 | IoWrite32 (\r | |
182 | IN UINTN Port,\r | |
2281e7a9 | 183 | IN UINT32 Value\r |
e1f414b6 | 184 | )\r |
185 | {\r | |
186 | ASSERT ((Port & 3) == 0);\r | |
187 | __asm__ __volatile__ ("outl %0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r | |
188 | return Value;\r | |
189 | }\r | |
190 | \r |