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