]>
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 | |
9095d37b | 11 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9344f092 | 12 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
e1f414b6 | 13 | \r |
e1f414b6 | 14 | **/\r |
15 | \r | |
16 | \r | |
1efcc4ae | 17 | \r |
f734a10a | 18 | #include "BaseIoLibIntrinsicInternal.h"\r |
e1f414b6 | 19 | \r |
20 | //\r | |
42eedea9 | 21 | // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.\r |
e1f414b6 | 22 | //\r |
42eedea9 | 23 | \r |
e1f414b6 | 24 | int _inp (unsigned short port);\r |
25 | unsigned short _inpw (unsigned short port);\r | |
26 | unsigned long _inpd (unsigned short port);\r | |
27 | int _outp (unsigned short port, int databyte );\r | |
28 | unsigned short _outpw (unsigned short port, unsigned short dataword );\r | |
29 | unsigned long _outpd (unsigned short port, unsigned long dataword );\r | |
30 | void _ReadWriteBarrier (void);\r | |
31 | \r | |
32 | #pragma intrinsic(_inp)\r | |
33 | #pragma intrinsic(_inpw)\r | |
34 | #pragma intrinsic(_inpd)\r | |
35 | #pragma intrinsic(_outp)\r | |
36 | #pragma intrinsic(_outpw)\r | |
37 | #pragma intrinsic(_outpd)\r | |
38 | #pragma intrinsic(_ReadWriteBarrier)\r | |
986352be | 39 | \r |
e1f414b6 | 40 | //\r |
41 | // _ReadWriteBarrier() forces memory reads and writes to complete at the point\r | |
42 | // in the call. This is only a hint to the compiler and does emit code.\r | |
43 | // In past versions of the compiler, _ReadWriteBarrier was enforced only\r | |
44 | // locally and did not affect functions up the call tree. In Visual C++\r | |
45 | // 2005, _ReadWriteBarrier is enforced all the way up the call tree.\r | |
46 | //\r | |
47 | \r | |
48 | /**\r | |
49 | Reads an 8-bit I/O port.\r | |
50 | \r | |
51 | Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r | |
52 | This function must guarantee that all I/O read and write operations are\r | |
53 | 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 read.\r | |
58 | \r | |
2281e7a9 | 59 | @return The value read.\r |
e1f414b6 | 60 | \r |
61 | **/\r | |
62 | UINT8\r | |
63 | EFIAPI\r | |
64 | IoRead8 (\r | |
65 | IN UINTN Port\r | |
66 | )\r | |
67 | {\r | |
68 | UINT8 Value;\r | |
69 | \r | |
70 | _ReadWriteBarrier ();\r | |
71 | Value = (UINT8)_inp ((UINT16)Port);\r | |
72 | _ReadWriteBarrier ();\r | |
73 | return Value;\r | |
74 | }\r | |
75 | \r | |
76 | /**\r | |
77 | Writes an 8-bit I/O port.\r | |
78 | \r | |
79 | Writes the 8-bit I/O port specified by Port with the value specified by Value\r | |
80 | and returns Value. This function must guarantee that all I/O read and write\r | |
81 | operations are serialized.\r | |
82 | \r | |
83 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
84 | \r | |
85 | @param Port The I/O port to write.\r | |
86 | @param Value The value to write to the I/O port.\r | |
87 | \r | |
35a17154 | 88 | @return The value written to the I/O port.\r |
e1f414b6 | 89 | \r |
90 | **/\r | |
91 | UINT8\r | |
92 | EFIAPI\r | |
93 | IoWrite8 (\r | |
94 | IN UINTN Port,\r | |
95 | IN UINT8 Value\r | |
96 | )\r | |
97 | {\r | |
98 | _ReadWriteBarrier ();\r | |
99 | (UINT8)_outp ((UINT16)Port, Value);\r | |
100 | _ReadWriteBarrier ();\r | |
101 | return Value;\r | |
102 | }\r | |
103 | \r | |
104 | /**\r | |
105 | Reads a 16-bit I/O port.\r | |
106 | \r | |
107 | Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r | |
108 | This function must guarantee that all I/O read and write operations are\r | |
109 | serialized.\r | |
110 | \r | |
111 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
2281e7a9 | 112 | If Port is not aligned on a 16-bit boundary, then ASSERT().\r |
e1f414b6 | 113 | \r |
114 | @param Port The I/O port to read.\r | |
115 | \r | |
2281e7a9 | 116 | @return The value read.\r |
e1f414b6 | 117 | \r |
118 | **/\r | |
119 | UINT16\r | |
120 | EFIAPI\r | |
121 | IoRead16 (\r | |
122 | IN UINTN Port\r | |
123 | )\r | |
124 | {\r | |
125 | UINT16 Value;\r | |
126 | \r | |
127 | ASSERT ((Port & 1) == 0);\r | |
128 | _ReadWriteBarrier ();\r | |
129 | Value = _inpw ((UINT16)Port);\r | |
130 | _ReadWriteBarrier ();\r | |
131 | return Value;\r | |
132 | }\r | |
133 | \r | |
134 | /**\r | |
135 | Writes a 16-bit I/O port.\r | |
136 | \r | |
137 | Writes the 16-bit I/O port specified by Port with the value specified by Value\r | |
138 | and returns Value. This function must guarantee that all I/O read and write\r | |
139 | operations are serialized.\r | |
140 | \r | |
141 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
2281e7a9 | 142 | If Port is not aligned on a 16-bit boundary, then ASSERT().\r |
9095d37b | 143 | \r |
e1f414b6 | 144 | @param Port The I/O port to write.\r |
145 | @param Value The value to write to the I/O port.\r | |
146 | \r | |
35a17154 | 147 | @return The value written to the I/O port.\r |
e1f414b6 | 148 | \r |
149 | **/\r | |
150 | UINT16\r | |
151 | EFIAPI\r | |
152 | IoWrite16 (\r | |
153 | IN UINTN Port,\r | |
154 | IN UINT16 Value\r | |
155 | )\r | |
156 | {\r | |
157 | ASSERT ((Port & 1) == 0);\r | |
158 | _ReadWriteBarrier ();\r | |
159 | _outpw ((UINT16)Port, Value);\r | |
160 | _ReadWriteBarrier ();\r | |
161 | return Value;\r | |
162 | }\r | |
163 | \r | |
164 | /**\r | |
165 | Reads a 32-bit I/O port.\r | |
166 | \r | |
167 | Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r | |
168 | This function must guarantee that all I/O read and write operations are\r | |
169 | serialized.\r | |
170 | \r | |
171 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
2281e7a9 | 172 | If Port is not aligned on a 32-bit boundary, then ASSERT().\r |
9095d37b | 173 | \r |
e1f414b6 | 174 | @param Port The I/O port to read.\r |
175 | \r | |
2281e7a9 | 176 | @return The value read.\r |
e1f414b6 | 177 | \r |
178 | **/\r | |
179 | UINT32\r | |
180 | EFIAPI\r | |
181 | IoRead32 (\r | |
182 | IN UINTN Port\r | |
183 | )\r | |
184 | {\r | |
185 | UINT32 Value;\r | |
186 | \r | |
187 | ASSERT ((Port & 3) == 0);\r | |
188 | _ReadWriteBarrier ();\r | |
189 | Value = _inpd ((UINT16)Port);\r | |
190 | _ReadWriteBarrier ();\r | |
191 | return Value;\r | |
192 | }\r | |
193 | \r | |
194 | /**\r | |
195 | Writes a 32-bit I/O port.\r | |
196 | \r | |
197 | Writes the 32-bit I/O port specified by Port with the value specified by Value\r | |
198 | and returns Value. This function must guarantee that all I/O read and write\r | |
199 | operations are serialized.\r | |
200 | \r | |
201 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
2281e7a9 | 202 | If Port is not aligned on a 32-bit boundary, then ASSERT().\r |
9095d37b | 203 | \r |
e1f414b6 | 204 | @param Port The I/O port to write.\r |
205 | @param Value The value to write to the I/O port.\r | |
206 | \r | |
35a17154 | 207 | @return The value written to the I/O port.\r |
e1f414b6 | 208 | \r |
209 | **/\r | |
210 | UINT32\r | |
211 | EFIAPI\r | |
212 | IoWrite32 (\r | |
213 | IN UINTN Port,\r | |
214 | IN UINT32 Value\r | |
215 | )\r | |
216 | {\r | |
217 | ASSERT ((Port & 3) == 0);\r | |
218 | _ReadWriteBarrier ();\r | |
219 | _outpd ((UINT16)Port, Value);\r | |
220 | _ReadWriteBarrier ();\r | |
221 | return Value;\r | |
222 | }\r |