]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibIcc.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLibIcc.c
1 /** @file
2 I/O Library. This file has compiler specifics for ICC as there
3 is no ANSI C standard for doing IO.
4
5 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "BaseIoLibIntrinsicInternal.h"
11
12 /**
13 Reads an 8-bit I/O port.
14
15 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
16 This function must guarantee that all I/O read and write operations are
17 serialized.
18
19 If 8-bit I/O port operations are not supported, then ASSERT().
20
21 @param Port The I/O port to read.
22
23 @return The value read.
24
25 **/
26 UINT8
27 EFIAPI
28 IoRead8 (
29 IN UINTN Port
30 )
31 {
32 UINT8 Data;
33
34 __asm {
35 mov dx, word ptr [Port]
36 in al, dx
37
38 mov Data, al
39 }
40 return Data;
41 }
42
43 /**
44 Writes an 8-bit I/O port.
45
46 Writes the 8-bit I/O port specified by Port with the value specified by Value
47 and returns Value. This function must guarantee that all I/O read and write
48 operations are serialized.
49
50 If 8-bit I/O port operations are not supported, then ASSERT().
51
52 @param Port The I/O port to write.
53 @param Value The value to write to the I/O port.
54
55 @return The value written the I/O port.
56
57 **/
58 UINT8
59 EFIAPI
60 IoWrite8 (
61 IN UINTN Port,
62 IN UINT8 Value
63 )
64 {
65 __asm {
66 mov al, byte ptr [Value]
67 mov dx, word ptr [Port]
68 out dx, al
69 }
70 return Value;
71 }
72
73 /**
74 Reads a 16-bit I/O port.
75
76 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
77 This function must guarantee that all I/O read and write operations are
78 serialized.
79
80 If 16-bit I/O port operations are not supported, then ASSERT().
81 If Port is not aligned on a 16-bit boundary, then ASSERT().
82
83 @param Port The I/O port to read.
84
85 @return The value read.
86
87 **/
88 UINT16
89 EFIAPI
90 IoRead16 (
91 IN UINTN Port
92 )
93 {
94 UINT16 Data;
95
96 ASSERT ((Port & 1) == 0);
97
98 __asm {
99 mov dx, word ptr [Port]
100 in ax, dx
101 mov word ptr [Data], ax
102 }
103
104 return Data;
105 }
106
107 /**
108 Writes a 16-bit I/O port.
109
110 Writes the 16-bit I/O port specified by Port with the value specified by Value
111 and returns Value. This function must guarantee that all I/O read and write
112 operations are serialized.
113
114 If 16-bit I/O port operations are not supported, then ASSERT().
115 If Port is not aligned on a 16-bit boundary, then ASSERT().
116
117 @param Port The I/O port to write.
118 @param Value The value to write to the I/O port.
119
120 @return The value written the I/O port.
121
122 **/
123 UINT16
124 EFIAPI
125 IoWrite16 (
126 IN UINTN Port,
127 IN UINT16 Value
128 )
129 {
130 ASSERT ((Port & 1) == 0);
131
132 __asm {
133 mov ax, word ptr [Value]
134 mov dx, word ptr [Port]
135 out dx, ax
136 }
137
138 return Value;
139 }
140
141 /**
142 Reads a 32-bit I/O port.
143
144 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
145 This function must guarantee that all I/O read and write operations are
146 serialized.
147
148 If 32-bit I/O port operations are not supported, then ASSERT().
149 If Port is not aligned on a 32-bit boundary, then ASSERT().
150
151 @param Port The I/O port to read.
152
153 @return The value read.
154
155 **/
156 UINT32
157 EFIAPI
158 IoRead32 (
159 IN UINTN Port
160 )
161 {
162 UINT32 Data;
163
164 ASSERT ((Port & 3) == 0);
165
166 __asm {
167 mov dx, word ptr [Port]
168 in eax, dx
169 mov dword ptr [Data], eax
170 }
171
172 return Data;
173 }
174
175 /**
176 Writes a 32-bit I/O port.
177
178 Writes the 32-bit I/O port specified by Port with the value specified by Value
179 and returns Value. This function must guarantee that all I/O read and write
180 operations are serialized.
181
182 If 32-bit I/O port operations are not supported, then ASSERT().
183 If Port is not aligned on a 32-bit boundary, then ASSERT().
184
185 @param Port The I/O port to write.
186 @param Value The value to write to the I/O port.
187
188 @return The value written the I/O port.
189
190 **/
191 UINT32
192 EFIAPI
193 IoWrite32 (
194 IN UINTN Port,
195 IN UINT32 Value
196 )
197 {
198 ASSERT ((Port & 3) == 0);
199
200 __asm {
201 mov eax, dword ptr [Value]
202 mov dx, word ptr [Port]
203 out dx, eax
204 }
205
206 return Value;
207 }
208