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