]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/CpuRuntimeDxe/CpuIo.c
4aaa431d540582b8d1a35d51f9b4b2acbb21c9f5
[mirror_edk2.git] / Nt32Pkg / CpuRuntimeDxe / CpuIo.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 CpuIo.c
15
16 Abstract:
17
18 This is the code that publishes the CPU I/O Protocol.
19 The intent herein is to have a single I/O service that can load
20 as early as possible, extend into runtime, and be layered upon by
21 the implementations of architectural protocols and the PCI Root
22 Bridge I/O Protocol.
23
24 --*/
25
26 #include <CpuDriver.h>
27
28 #define IA32_MAX_IO_ADDRESS 0xFFFF
29 #define IA32_MAX_MEM_ADDRESS 0xFFFFFFFF
30
31 EFI_CPU_IO_PROTOCOL mCpuIoProtocol;
32
33 EFI_STATUS
34 CpuIoCheckAddressRange (
35 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
36 IN UINT64 Address,
37 IN UINTN Count,
38 IN VOID *Buffer,
39 IN UINT64 Limit
40 );
41
42 EFI_STATUS
43 EFIAPI
44 CpuMemoryServiceRead (
45 IN EFI_CPU_IO_PROTOCOL *This,
46 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
47 IN UINT64 Address,
48 IN UINTN Count,
49 IN OUT VOID *Buffer
50 )
51 /*++
52
53 Routine Description:
54
55 Perform the Memory Access Read service for the CPU I/O Protocol
56
57 Arguments:
58
59 Pointer to an instance of the CPU I/O Protocol
60 Width of the Memory Access
61 Address of the Memory access
62 Count of the number of accesses to perform
63 Pointer to the buffer to read or write from memory
64
65 Returns:
66
67 Status
68
69 EFI_SUCCESS - The data was read from or written to the EFI
70 System.
71 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
72 EFI_INVALID_PARAMETER - Buffer is NULL.
73 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
74 EFI_UNSUPPORTED - The address range specified by Address, Width,
75 and Count is not valid for this EFI System.
76
77 --*/
78 // TODO: This - add argument and description to function comment
79 {
80 EFI_STATUS Status;
81
82 if (!Buffer) {
83 return EFI_INVALID_PARAMETER;
84 }
85
86 Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);
87 if (EFI_ERROR (Status)) {
88 return Status;
89 }
90
91 //
92 // Do nothing for Nt32 version
93 //
94 return EFI_SUCCESS;
95 }
96
97 EFI_STATUS
98 EFIAPI
99 CpuMemoryServiceWrite (
100 IN EFI_CPU_IO_PROTOCOL *This,
101 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
102 IN UINT64 Address,
103 IN UINTN Count,
104 IN OUT VOID *Buffer
105 )
106 /*++
107
108 Routine Description:
109
110 Perform the Memory Access Read service for the CPU I/O Protocol
111
112 Arguments:
113
114 Pointer to an instance of the CPU I/O Protocol
115 Width of the Memory Access
116 Address of the Memory access
117 Count of the number of accesses to perform
118 Pointer to the buffer to read or write from memory
119
120 Returns:
121
122 Status
123
124 EFI_SUCCESS - The data was read from or written to the EFI System.
125 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
126 EFI_INVALID_PARAMETER - Buffer is NULL.
127 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
128 EFI_UNSUPPORTED - The address range specified by Address, Width, and
129 Count is not valid for this EFI System.
130
131 --*/
132 // TODO: This - add argument and description to function comment
133 {
134 EFI_STATUS Status;
135
136 if (!Buffer) {
137 return EFI_INVALID_PARAMETER;
138 }
139
140 Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);
141 if (EFI_ERROR (Status)) {
142 return Status;
143 }
144
145 //
146 // Do nothing for Nt32 version
147 //
148 return EFI_SUCCESS;
149 }
150
151 EFI_STATUS
152 EFIAPI
153 CpuIoServiceRead (
154 IN EFI_CPU_IO_PROTOCOL *This,
155 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
156 IN UINT64 UserAddress,
157 IN UINTN Count,
158 IN OUT VOID *UserBuffer
159 )
160 /*++
161
162 Routine Description:
163
164 This is the service that implements the I/O read
165
166 Arguments:
167
168 Pointer to an instance of the CPU I/O Protocol
169 Width of the Memory Access
170 Address of the I/O access
171 Count of the number of accesses to perform
172 Pointer to the buffer to read or write from I/O space
173
174 Returns:
175
176 Status
177 EFI_SUCCESS - The data was read from or written to the EFI System.
178 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
179 EFI_INVALID_PARAMETER - Buffer is NULL.
180 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
181 EFI_UNSUPPORTED - The address range specified by Address, Width, and
182 Count is not valid for this EFI System.
183 --*/
184 // TODO: This - add argument and description to function comment
185 // TODO: UserAddress - add argument and description to function comment
186 // TODO: UserBuffer - add argument and description to function comment
187 {
188 UINTN Address;
189 EFI_STATUS Status;
190
191 if (!UserBuffer) {
192 return EFI_INVALID_PARAMETER;
193 }
194
195 Address = (UINTN) UserAddress;
196
197 if (Width >= EfiCpuIoWidthMaximum) {
198 return EFI_INVALID_PARAMETER;
199 }
200
201 Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);
202 if (EFI_ERROR (Status)) {
203 return Status;
204 }
205
206 //
207 // Do nothing for Nt32 version
208 //
209 return EFI_SUCCESS;
210 }
211
212 EFI_STATUS
213 EFIAPI
214 CpuIoServiceWrite (
215 IN EFI_CPU_IO_PROTOCOL *This,
216 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
217 IN UINT64 UserAddress,
218 IN UINTN Count,
219 IN OUT VOID *UserBuffer
220 )
221 /*++
222
223 Routine Description:
224
225
226 This is the service that implements the I/O Write
227
228 Arguments:
229
230 Pointer to an instance of the CPU I/O Protocol
231 Width of the Memory Access
232 Address of the I/O access
233 Count of the number of accesses to perform
234 Pointer to the buffer to read or write from I/O space
235
236 Returns:
237
238 Status
239
240 Status
241 EFI_SUCCESS - The data was read from or written to the EFI System.
242 EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
243 EFI_INVALID_PARAMETER - Buffer is NULL.
244 EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
245 EFI_UNSUPPORTED - The address range specified by Address, Width, and
246 Count is not valid for this EFI System.
247
248 --*/
249 // TODO: This - add argument and description to function comment
250 // TODO: UserAddress - add argument and description to function comment
251 // TODO: UserBuffer - add argument and description to function comment
252 {
253 UINTN Address;
254 EFI_STATUS Status;
255
256 if (!UserBuffer) {
257 return EFI_INVALID_PARAMETER;
258 }
259
260 Address = (UINTN) UserAddress;
261
262 if (Width >= EfiCpuIoWidthMaximum) {
263 return EFI_INVALID_PARAMETER;
264 }
265
266 Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);
267 if (EFI_ERROR (Status)) {
268 return Status;
269 }
270
271 //
272 // Do nothing for Nt32 version
273 //
274 return EFI_SUCCESS;
275 }
276
277
278 EFI_STATUS
279 CpuIoCheckAddressRange (
280 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
281 IN UINT64 Address,
282 IN UINTN Count,
283 IN VOID *Buffer,
284 IN UINT64 Limit
285 )
286 /*++
287
288 Routine Description:
289
290 TODO: Add function description
291
292 Arguments:
293
294 Width - TODO: add argument description
295 Address - TODO: add argument description
296 Count - TODO: add argument description
297 Buffer - TODO: add argument description
298 Limit - TODO: add argument description
299
300 Returns:
301
302 EFI_UNSUPPORTED - TODO: Add description for return value
303 EFI_UNSUPPORTED - TODO: Add description for return value
304 EFI_UNSUPPORTED - TODO: Add description for return value
305 EFI_SUCCESS - TODO: Add description for return value
306
307 --*/
308 {
309 UINTN AlignMask;
310
311 if (Address > Limit) {
312 return EFI_UNSUPPORTED;
313 }
314
315 //
316 // For FiFo type, the target address won't increase during the access, so treat count as 1
317 //
318 if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {
319 Count = 1;
320 }
321
322 Width = Width & 0x03;
323 if (Address - 1 + (1 << Width) * Count > Limit) {
324 return EFI_UNSUPPORTED;
325 }
326
327 AlignMask = (1 << Width) - 1;
328 if ((UINTN) Buffer & AlignMask) {
329 return EFI_UNSUPPORTED;
330 }
331
332 return EFI_SUCCESS;
333 }
334
335