]>
Commit | Line | Data |
---|---|---|
c3902377 | 1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved. <BR> \r | |
4 | This software and associated documentation (if any) is furnished\r | |
5 | under a license and may only be used or copied in accordance\r | |
6 | with the terms of the license. Except as permitted by such\r | |
7 | license, no part of this software or documentation may be\r | |
8 | reproduced, stored in a retrieval system, or transmitted in any\r | |
9 | form or by any means without the express written consent of\r | |
10 | Intel Corporation.\r | |
11 | \r | |
12 | \r | |
13 | Module Name:\r | |
14 | \r | |
15 | IsaIo.c\r | |
16 | \r | |
17 | Abstract:\r | |
18 | \r | |
19 | The implementation for EFI_ISA_IO_PROTOCOL. \r | |
20 | \r | |
21 | --*/\r | |
22 | \r | |
23 | //\r | |
24 | // Include common header file for this module.\r | |
25 | //\r | |
26 | #include "InternalIsaIo.h"\r | |
27 | \r | |
28 | #include <IndustryStandard/Pcat.h>\r | |
29 | \r | |
30 | //\r | |
31 | // Driver Support Global Variables\r | |
32 | //\r | |
33 | EFI_ISA_IO_PROTOCOL IsaIoInterface = {\r | |
34 | { \r | |
35 | IsaIoMemRead,\r | |
36 | IsaIoMemWrite\r | |
37 | },\r | |
38 | { \r | |
39 | IsaIoIoRead,\r | |
40 | IsaIoIoWrite\r | |
41 | },\r | |
42 | IsaIoCopyMem,\r | |
43 | IsaIoMap,\r | |
44 | IsaIoUnmap,\r | |
45 | IsaIoAllocateBuffer,\r | |
46 | IsaIoFreeBuffer,\r | |
47 | IsaIoFlush,\r | |
48 | NULL,\r | |
49 | 0,\r | |
50 | NULL\r | |
51 | };\r | |
52 | \r | |
53 | static EFI_ISA_DMA_REGISTERS DmaRegisters[8] = {\r | |
54 | {\r | |
55 | 0x00,\r | |
56 | 0x87,\r | |
57 | 0x01\r | |
58 | },\r | |
59 | {\r | |
60 | 0x02,\r | |
61 | 0x83,\r | |
62 | 0x03\r | |
63 | },\r | |
64 | {\r | |
65 | 0x04,\r | |
66 | 0x81,\r | |
67 | 0x05\r | |
68 | },\r | |
69 | {\r | |
70 | 0x06,\r | |
71 | 0x82,\r | |
72 | 0x07\r | |
73 | },\r | |
74 | {\r | |
75 | 0x00,\r | |
76 | 0x00,\r | |
77 | 0x00\r | |
78 | }, // Channel 4 is invalid\r | |
79 | {\r | |
80 | 0xC4,\r | |
81 | 0x8B,\r | |
82 | 0xC6\r | |
83 | },\r | |
84 | {\r | |
85 | 0xC8,\r | |
86 | 0x89,\r | |
87 | 0xCA\r | |
88 | },\r | |
89 | {\r | |
90 | 0xCC,\r | |
91 | 0x8A,\r | |
92 | 0xCE\r | |
93 | },\r | |
94 | };\r | |
95 | \r | |
96 | EFI_STATUS\r | |
97 | ReportErrorStatusCode (\r | |
98 | EFI_STATUS_CODE_VALUE Code\r | |
99 | )\r | |
100 | /*++\r | |
101 | \r | |
102 | Routine Description:\r | |
103 | \r | |
104 | report a error Status code of PCI bus driver controller\r | |
105 | \r | |
106 | Arguments:\r | |
107 | \r | |
108 | Code - The error status code.\r | |
109 | \r | |
110 | Returns:\r | |
111 | \r | |
112 | EFI_SUCCESS - Success to report status code.\r | |
113 | \r | |
114 | \r | |
115 | --*/\r | |
116 | {\r | |
117 | return REPORT_STATUS_CODE (\r | |
118 | EFI_ERROR_CODE | EFI_ERROR_MINOR,\r | |
119 | Code\r | |
120 | );\r | |
121 | }\r | |
122 | \r | |
123 | //\r | |
124 | // Driver Support Functions\r | |
125 | //\r | |
126 | \r | |
127 | EFI_STATUS\r | |
128 | InitializeIsaIoInstance (\r | |
129 | IN ISA_IO_DEVICE *IsaIoDevice,\r | |
130 | IN EFI_ISA_ACPI_RESOURCE_LIST *IsaDeviceResourceList\r | |
131 | )\r | |
132 | /*++\r | |
133 | \r | |
134 | Routine Description:\r | |
135 | \r | |
136 | Initializes an ISA I/O Instance\r | |
137 | \r | |
138 | Arguments:\r | |
139 | \r | |
140 | IsaIoDevice - The iso device to be initialized.\r | |
141 | IsaDeviceResourceList - The resource list.\r | |
142 | \r | |
143 | Returns:\r | |
144 | \r | |
145 | EFI_SUCCESS - Initial success.\r | |
146 | \r | |
147 | --*/\r | |
148 | {\r | |
149 | //\r | |
150 | // Initializes an ISA I/O Instance\r | |
151 | //\r | |
152 | CopyMem (\r | |
153 | &IsaIoDevice->IsaIo,\r | |
154 | &IsaIoInterface,\r | |
155 | sizeof (EFI_ISA_IO_PROTOCOL)\r | |
156 | );\r | |
157 | \r | |
158 | IsaIoDevice->IsaIo.ResourceList = IsaDeviceResourceList;\r | |
159 | \r | |
160 | return EFI_SUCCESS;\r | |
161 | }\r | |
162 | \r | |
163 | EFI_STATUS\r | |
164 | EFIAPI\r | |
165 | IsaIoIoRead (\r | |
166 | IN EFI_ISA_IO_PROTOCOL *This,\r | |
167 | IN EFI_ISA_IO_PROTOCOL_WIDTH Width,\r | |
168 | IN UINT32 Offset,\r | |
169 | IN UINTN Count,\r | |
170 | IN OUT VOID *Buffer\r | |
171 | )\r | |
172 | /*++\r | |
173 | \r | |
174 | Routine Description:\r | |
175 | \r | |
176 | Performs an ISA I/O Read Cycle\r | |
177 | \r | |
178 | Arguments:\r | |
179 | \r | |
180 | This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r | |
181 | Width - Signifies the width of the I/O operation.\r | |
182 | Offset - The offset in ISA I/O space to start the I/O operation. \r | |
183 | Count - The number of I/O operations to perform. \r | |
184 | Buffer - The destination buffer to store the results\r | |
185 | \r | |
186 | Returns:\r | |
187 | \r | |
188 | EFI_SUCCESS - The data was read from the device sucessfully.\r | |
189 | EFI_UNSUPPORTED - The Offset is not valid for this device.\r | |
190 | EFI_INVALID_PARAMETER - Width or Count, or both, were invalid.\r | |
191 | EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r | |
192 | \r | |
193 | --*/\r | |
194 | {\r | |
195 | EFI_STATUS Status;\r | |
196 | ISA_IO_DEVICE *IsaIoDevice;\r | |
197 | \r | |
198 | IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);\r | |
199 | \r | |
200 | //\r | |
201 | // Verify Isa IO Access\r | |
202 | //\r | |
203 | Status = IsaIoVerifyAccess (\r | |
204 | IsaIoDevice,\r | |
205 | IsaAccessTypeIo,\r | |
206 | Width,\r | |
207 | Count,\r | |
208 | &Offset\r | |
209 | );\r | |
210 | if (EFI_ERROR (Status)) {\r | |
211 | return Status;\r | |
212 | }\r | |
213 | //\r | |
214 | // Call PciIo->Io.Read\r | |
215 | //\r | |
216 | Status = IsaIoDevice->PciIo->Io.Read (\r | |
217 | IsaIoDevice->PciIo,\r | |
218 | (EFI_PCI_IO_PROTOCOL_WIDTH) Width,\r | |
219 | EFI_PCI_IO_PASS_THROUGH_BAR,\r | |
220 | Offset,\r | |
221 | Count,\r | |
222 | Buffer\r | |
223 | );\r | |
224 | \r | |
225 | if (EFI_ERROR (Status)) {\r | |
226 | ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r | |
227 | }\r | |
228 | \r | |
229 | return Status;\r | |
230 | }\r | |
231 | \r | |
232 | EFI_STATUS\r | |
233 | EFIAPI\r | |
234 | IsaIoIoWrite (\r | |
235 | IN EFI_ISA_IO_PROTOCOL *This,\r | |
236 | IN EFI_ISA_IO_PROTOCOL_WIDTH Width,\r | |
237 | IN UINT32 Offset,\r | |
238 | IN UINTN Count,\r | |
239 | IN OUT VOID *Buffer\r | |
240 | )\r | |
241 | /*++\r | |
242 | \r | |
243 | Routine Description:\r | |
244 | \r | |
245 | Performs an ISA I/O Write Cycle\r | |
246 | \r | |
247 | Arguments:\r | |
248 | \r | |
249 | This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r | |
250 | Width - Signifies the width of the I/O operation.\r | |
251 | Offset - The offset in ISA I/O space to start the I/O operation. \r | |
252 | Count - The number of I/O operations to perform. \r | |
253 | Buffer - The source buffer to write data from\r | |
254 | \r | |
255 | Returns:\r | |
256 | \r | |
257 | EFI_SUCCESS - The data was writen to the device sucessfully.\r | |
258 | EFI_UNSUPPORTED - The Offset is not valid for this device.\r | |
259 | EFI_INVALID_PARAMETER - Width or Count, or both, were invalid.\r | |
260 | EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r | |
261 | \r | |
262 | --*/\r | |
263 | {\r | |
264 | EFI_STATUS Status;\r | |
265 | ISA_IO_DEVICE *IsaIoDevice;\r | |
266 | \r | |
267 | IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);\r | |
268 | \r | |
269 | //\r | |
270 | // Verify Isa IO Access\r | |
271 | //\r | |
272 | Status = IsaIoVerifyAccess (\r | |
273 | IsaIoDevice,\r | |
274 | IsaAccessTypeIo,\r | |
275 | Width,\r | |
276 | Count,\r | |
277 | &Offset\r | |
278 | );\r | |
279 | if (EFI_ERROR (Status)) {\r | |
280 | return Status;\r | |
281 | }\r | |
282 | //\r | |
283 | // Call PciIo->Io.Write\r | |
284 | //\r | |
285 | Status = IsaIoDevice->PciIo->Io.Write (\r | |
286 | IsaIoDevice->PciIo,\r | |
287 | (EFI_PCI_IO_PROTOCOL_WIDTH) Width,\r | |
288 | EFI_PCI_IO_PASS_THROUGH_BAR,\r | |
289 | Offset,\r | |
290 | Count,\r | |
291 | Buffer\r | |
292 | );\r | |
293 | \r | |
294 | if (EFI_ERROR (Status)) {\r | |
295 | ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r | |
296 | }\r | |
297 | \r | |
298 | return Status;\r | |
299 | }\r | |
300 | \r | |
301 | EFI_STATUS\r | |
302 | WritePort (\r | |
303 | IN EFI_ISA_IO_PROTOCOL *This,\r | |
304 | IN UINT32 Offset,\r | |
305 | IN UINT8 Value\r | |
306 | )\r | |
307 | /*++\r | |
308 | \r | |
309 | Routine Description:\r | |
310 | \r | |
311 | Writes an 8 bit I/O Port\r | |
312 | \r | |
313 | Arguments:\r | |
314 | \r | |
315 | This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r | |
316 | Offset - The offset in ISA IO space to start the IO operation. \r | |
317 | Value - The data to write port.\r | |
318 | \r | |
319 | Returns:\r | |
320 | \r | |
321 | EFI_SUCCESS - Success.\r | |
322 | EFI_INVALID_PARAMETER - Parameter is invalid.\r | |
323 | EFI_UNSUPPORTED - The address range specified by Offset is not valid.\r | |
324 | EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r | |
325 | \r | |
326 | --*/\r | |
327 | {\r | |
328 | EFI_STATUS Status;\r | |
329 | ISA_IO_DEVICE *IsaIoDevice;\r | |
330 | \r | |
331 | IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);\r | |
332 | \r | |
333 | //\r | |
334 | // Call PciIo->Io.Write\r | |
335 | //\r | |
336 | Status = IsaIoDevice->PciIo->Io.Write (\r | |
337 | IsaIoDevice->PciIo,\r | |
338 | EfiPciIoWidthUint8,\r | |
339 | EFI_PCI_IO_PASS_THROUGH_BAR,\r | |
340 | Offset,\r | |
341 | 1,\r | |
342 | &Value\r | |
343 | );\r | |
344 | if (EFI_ERROR (Status)) {\r | |
345 | ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r | |
346 | return Status;\r | |
347 | }\r | |
348 | \r | |
349 | gBS->Stall (50);\r | |
350 | \r | |
351 | return EFI_SUCCESS;\r | |
352 | }\r | |
353 | \r | |
354 | EFI_STATUS\r | |
355 | WriteDmaPort (\r | |
356 | IN EFI_ISA_IO_PROTOCOL *This,\r | |
357 | IN UINT32 AddrOffset,\r | |
358 | IN UINT32 PageOffset,\r | |
359 | IN UINT32 CountOffset,\r | |
360 | IN UINT32 BaseAddress,\r | |
361 | IN UINT16 Count\r | |
362 | )\r | |
363 | /*++\r | |
364 | \r | |
365 | Routine Description:\r | |
366 | \r | |
367 | Writes I/O operation base address and count number to a 8 bit I/O Port.\r | |
368 | \r | |
369 | Arguments:\r | |
370 | \r | |
371 | This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r | |
372 | AddrOffset - The address' offset.\r | |
373 | PageOffset - The page's offest.\r | |
374 | CountOffset - The count's offset.\r | |
375 | BaseAddress - The base address.\r | |
376 | Count - The number of I/O operations to perform. \r | |
377 | \r | |
378 | Returns:\r | |
379 | \r | |
380 | EFI_SUCCESS - Success.\r | |
381 | EFI_INVALID_PARAMETER - Parameter is invalid.\r | |
382 | EFI_UNSUPPORTED - The address range specified by these Offsets and Count is not valid.\r | |
383 | EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r | |
384 | \r | |
385 | --*/\r | |
386 | {\r | |
387 | EFI_STATUS Status;\r | |
388 | \r | |
389 | Status = WritePort (This, AddrOffset, (UINT8) (BaseAddress & 0xff));\r | |
390 | if (EFI_ERROR (Status)) {\r | |
391 | return Status;\r | |
392 | }\r | |
393 | \r | |
394 | Status = WritePort (This, AddrOffset, (UINT8) ((BaseAddress >> 8) & 0xff));\r | |
395 | if (EFI_ERROR (Status)) {\r | |
396 | return Status;\r | |
397 | }\r | |
398 | \r | |
399 | Status = WritePort (This, PageOffset, (UINT8) ((BaseAddress >> 16) & 0xff));\r | |
400 | if (EFI_ERROR (Status)) {\r | |
401 | return Status;\r | |
402 | }\r | |
403 | \r | |
404 | Status = WritePort (This, CountOffset, (UINT8) (Count & 0xff));\r | |
405 | if (EFI_ERROR (Status)) {\r | |
406 | return Status;\r | |
407 | }\r | |
408 | \r | |
409 | Status = WritePort (This, CountOffset, (UINT8) ((Count >> 8) & 0xff));\r | |
410 | if (EFI_ERROR (Status)) {\r | |
411 | return Status;\r | |
412 | }\r | |
413 | \r | |
414 | return EFI_SUCCESS;\r | |
415 | }\r | |
416 | \r | |
417 | EFI_STATUS\r | |
418 | EFIAPI\r | |
419 | IsaIoUnmap (\r | |
420 | IN EFI_ISA_IO_PROTOCOL *This,\r | |
421 | IN VOID *Mapping\r | |
422 | )\r | |
423 | /*++\r | |
424 | \r | |
425 | Routine Description:\r | |
426 | \r | |
427 | Unmaps a memory region for DMA\r | |
428 | \r | |
429 | Arguments:\r | |
430 | \r | |
431 | This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r | |
432 | Mapping - The mapping value returned from EFI_ISA_IO.Map().\r | |
433 | \r | |
434 | Returns:\r | |
435 | \r | |
436 | EFI_SUCCESS - The range was unmapped.\r | |
437 | EFI_DEVICE_ERROR - The data was not committed to the target system memory.\r | |
438 | \r | |
439 | --*/\r | |
440 | {\r | |
441 | ISA_MAP_INFO *IsaMapInfo;\r | |
442 | \r | |
443 | //\r | |
444 | // Unset Feature Flag PcdIsaBusSupportDma to disable support for ISA DMA.\r | |
445 | //\r | |
446 | if (!FeaturePcdGet (PcdIsaBusSupportDma)) {\r | |
447 | return EFI_UNSUPPORTED;\r | |
448 | }\r | |
449 | \r | |
450 | //\r | |
451 | // See if the Map() operation associated with this Unmap() required a mapping\r | |
452 | // buffer.If a mapping buffer was not required, then this function simply\r | |
453 | // returns EFI_SUCCESS.\r | |
454 | //\r | |
455 | if (Mapping != NULL) {\r | |
456 | //\r | |
457 | // Get the MAP_INFO structure from Mapping\r | |
458 | //\r | |
459 | IsaMapInfo = (ISA_MAP_INFO *) Mapping;\r | |
460 | \r | |
461 | //\r | |
462 | // If this is a write operation from the Agent's point of view,\r | |
463 | // then copy the contents of the mapped buffer into the real buffer\r | |
464 | // so the processor can read the contents of the real buffer.\r | |
465 | //\r | |
466 | if (IsaMapInfo->Operation == EfiIsaIoOperationBusMasterWrite) {\r | |
467 | CopyMem (\r | |
468 | (VOID *) (UINTN) IsaMapInfo->HostAddress,\r | |
469 | (VOID *) (UINTN) IsaMapInfo->MappedHostAddress,\r | |
470 | IsaMapInfo->NumberOfBytes\r | |
471 | );\r | |
472 | }\r | |
473 | //\r | |
474 | // Free the mapped buffer and the MAP_INFO structure.\r | |
475 | //\r | |
476 | gBS->FreePages (IsaMapInfo->MappedHostAddress, IsaMapInfo->NumberOfPages);\r | |
477 | gBS->FreePool (IsaMapInfo);\r | |
478 | }\r | |
479 | \r | |
480 | return EFI_SUCCESS;\r | |
481 | }\r | |
482 | \r | |
483 | EFI_STATUS\r | |
484 | EFIAPI\r | |
485 | IsaIoFlush (\r | |
486 | IN EFI_ISA_IO_PROTOCOL *This\r | |
487 | )\r | |
488 | /*++\r | |
489 | \r | |
490 | Routine Description:\r | |
491 | \r | |
492 | Flushes a DMA buffer\r | |
493 | \r | |
494 | Arguments:\r | |
495 | \r | |
496 | This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r | |
497 | \r | |
498 | Returns:\r | |
499 | \r | |
500 | EFI_SUCCESS - The buffers were flushed.\r | |
501 | EFI_DEVICE_ERROR - The buffers were not flushed due to a hardware error.\r | |
502 | \r | |
503 | --*/\r | |
504 | {\r | |
505 | EFI_STATUS Status;\r | |
506 | ISA_IO_DEVICE *IsaIoDevice;\r | |
507 | \r | |
508 | IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);\r | |
509 | \r | |
510 | //\r | |
511 | // Call PciIo->Flush\r | |
512 | //\r | |
513 | Status = IsaIoDevice->PciIo->Flush (IsaIoDevice->PciIo);\r | |
514 | \r | |
515 | if (EFI_ERROR (Status)) {\r | |
516 | ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r | |
517 | }\r | |
518 | \r | |
519 | return Status;\r | |
520 | }\r | |
521 | \r | |
522 | EFI_STATUS\r | |
523 | IsaIoVerifyAccess (\r | |
524 | IN ISA_IO_DEVICE *IsaIoDevice,\r | |
525 | IN ISA_ACCESS_TYPE Type,\r | |
526 | IN EFI_ISA_IO_PROTOCOL_WIDTH Width,\r | |
527 | IN UINTN Count,\r | |
528 | IN OUT UINT32 *Offset\r | |
529 | )\r | |
530 | /*++\r | |
531 | \r | |
532 | Routine Description:\r | |
533 | \r | |
534 | Verifies access to an ISA device\r | |
535 | \r | |
536 | Arguments:\r | |
537 | \r | |
538 | IsaIoDevice - The ISA device to be verified.\r | |
539 | Type - The Access type. The input must be either IsaAccessTypeMem or IsaAccessTypeIo.\r | |
540 | Width - Signifies the width of the memory operation.\r | |
541 | Count - The number of memory operations to perform. \r | |
542 | Offset - The offset in ISA memory space to start the memory operation. \r | |
543 | \r | |
544 | Returns:\r | |
545 | \r | |
546 | EFI_SUCCESS - Verify success.\r | |
547 | EFI_INVALID_PARAMETER - One of the parameters has an invalid value.\r | |
548 | EFI_UNSUPPORTED - The device ont support the access type.\r | |
549 | \r | |
550 | --*/\r | |
551 | {\r | |
552 | EFI_ISA_ACPI_RESOURCE *Item;\r | |
553 | EFI_STATUS Status;\r | |
554 | \r | |
555 | if (Width < EfiIsaIoWidthUint8 ||\r | |
556 | Width >= EfiIsaIoWidthMaximum ||\r | |
557 | Width == EfiIsaIoWidthReserved ||\r | |
558 | Width == EfiIsaIoWidthFifoReserved ||\r | |
559 | Width == EfiIsaIoWidthFillReserved\r | |
560 | ) {\r | |
561 | return EFI_INVALID_PARAMETER;\r | |
562 | }\r | |
563 | \r | |
564 | //\r | |
565 | // If Width is EfiIsaIoWidthFifoUintX then convert to EfiIsaIoWidthUintX\r | |
566 | // If Width is EfiIsaIoWidthFillUintX then convert to EfiIsaIoWidthUintX\r | |
567 | //\r | |
568 | if (Width >= EfiIsaIoWidthFifoUint8 && Width <= EfiIsaIoWidthFifoReserved) {\r | |
569 | Count = 1;\r | |
570 | }\r | |
571 | \r | |
572 | Width = (EFI_ISA_IO_PROTOCOL_WIDTH) (Width & 0x03);\r | |
573 | \r | |
574 | Status = EFI_UNSUPPORTED;\r | |
575 | Item = IsaIoDevice->IsaIo.ResourceList->ResourceItem;\r | |
576 | while (Item->Type != EfiIsaAcpiResourceEndOfList) {\r | |
577 | if ((Type == IsaAccessTypeMem && Item->Type == EfiIsaAcpiResourceMemory) ||\r | |
578 | (Type == IsaAccessTypeIo && Item->Type == EfiIsaAcpiResourceIo)\r | |
579 | ) {\r | |
580 | if (*Offset >= Item->StartRange && (*Offset + Count * (UINT32)(1 << Width)) - 1 <= Item->EndRange) {\r | |
581 | return EFI_SUCCESS;\r | |
582 | }\r | |
583 | \r | |
584 | if (*Offset >= Item->StartRange && *Offset <= Item->EndRange) {\r | |
585 | Status = EFI_INVALID_PARAMETER;\r | |
586 | }\r | |
587 | }\r | |
588 | \r | |
589 | Item++;\r | |
590 | }\r | |
591 | \r | |
592 | return Status;\r | |
593 | }\r | |
594 | \r | |
595 | EFI_STATUS\r | |
596 | EFIAPI\r | |
597 | IsaIoMemRead (\r | |
598 | IN EFI_ISA_IO_PROTOCOL *This,\r | |
599 | IN EFI_ISA_IO_PROTOCOL_WIDTH Width,\r | |
600 | IN UINT32 Offset,\r | |
601 | IN UINTN Count,\r | |
602 | IN OUT VOID *Buffer\r | |
603 | )\r | |
604 | /*++\r | |
605 | \r | |
606 | Routine Description:\r | |
607 | \r | |
608 | Performs an ISA Memory Read Cycle\r | |
609 | \r | |
610 | Arguments:\r | |
611 | \r | |
612 | This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r | |
613 | Width - Signifies the width of the memory operation.\r | |
614 | Offset - The offset in ISA memory space to start the memory operation. \r | |
615 | Count - The number of memory operations to perform. \r | |
616 | Buffer - The destination buffer to store the results\r | |
617 | \r | |
618 | Returns:\r | |
619 | \r | |
620 | EFI_SUCCESS - The data was read from the device successfully.\r | |
621 | EFI_UNSUPPORTED - The Offset is not valid for this device.\r | |
622 | EFI_INVALID_PARAMETER - Width or Count, or both, were invalid.\r | |
623 | EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r | |
624 | \r | |
625 | --*/\r | |
626 | {\r | |
627 | EFI_STATUS Status;\r | |
628 | ISA_IO_DEVICE *IsaIoDevice;\r | |
629 | \r | |
630 | //\r | |
631 | // Set Feature Flag PcdIsaBusSupportBusMaster to FALSE to disable support for \r | |
632 | // ISA Bus Master.\r | |
633 | //\r | |
634 | // So we just return EFI_UNSUPPORTED for these functions.\r | |
635 | //\r | |
636 | if (!FeaturePcdGet (PcdIsaBusSupportIsaMemory)) {\r | |
637 | return EFI_UNSUPPORTED;\r | |
638 | }\r | |
639 | \r | |
640 | IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);\r | |
641 | \r | |
642 | //\r | |
643 | // Verify the Isa Io Access\r | |
644 | //\r | |
645 | Status = IsaIoVerifyAccess (\r | |
646 | IsaIoDevice,\r | |
647 | IsaAccessTypeMem,\r | |
648 | Width,\r | |
649 | Count,\r | |
650 | &Offset\r | |
651 | );\r | |
652 | if (EFI_ERROR (Status)) {\r | |
653 | return Status;\r | |
654 | }\r | |
655 | //\r | |
656 | // Call PciIo->Mem.Read\r | |
657 | //\r | |
658 | Status = IsaIoDevice->PciIo->Mem.Read (\r | |
659 | IsaIoDevice->PciIo,\r | |
660 | (EFI_PCI_IO_PROTOCOL_WIDTH) Width,\r | |
661 | EFI_PCI_IO_PASS_THROUGH_BAR,\r | |
662 | Offset,\r | |
663 | Count,\r | |
664 | Buffer\r | |
665 | );\r | |
666 | \r | |
667 | if (EFI_ERROR (Status)) {\r | |
668 | ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r | |
669 | }\r | |
670 | \r | |
671 | return Status;\r | |
672 | }\r | |
673 | \r | |
674 | EFI_STATUS\r | |
675 | EFIAPI\r | |
676 | IsaIoMemWrite (\r | |
677 | IN EFI_ISA_IO_PROTOCOL *This,\r | |
678 | IN EFI_ISA_IO_PROTOCOL_WIDTH Width,\r | |
679 | IN UINT32 Offset,\r | |
680 | IN UINTN Count,\r | |
681 | IN OUT VOID *Buffer\r | |
682 | )\r | |
683 | /*++\r | |
684 | \r | |
685 | Routine Description:\r | |
686 | \r | |
687 | Performs an ISA Memory Write Cycle\r | |
688 | \r | |
689 | Arguments:\r | |
690 | \r | |
691 | This - A pointer to the EFI_ISA_IO_PROTOCOL instance. \r | |
692 | Width - Signifies the width of the memory operation.\r | |
693 | Offset - The offset in ISA memory space to start the memory operation. \r | |
694 | Count - The number of memory operations to perform. \r | |
695 | Buffer - The source buffer to write data from\r | |
696 | \r | |
697 | Returns:\r | |
698 | \r | |
699 | EFI_SUCCESS - The data was written to the device sucessfully.\r | |
700 | EFI_UNSUPPORTED - The Offset is not valid for this device.\r | |
701 | EFI_INVALID_PARAMETER - Width or Count, or both, were invalid.\r | |
702 | EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r | |
703 | \r | |
704 | --*/\r | |
705 | {\r | |
706 | EFI_STATUS Status;\r | |
707 | ISA_IO_DEVICE *IsaIoDevice;\r | |
708 | \r | |
709 | //\r | |
710 | // Set Feature Flag PcdIsaBusSupportBusMaster to FALSE to disable support for \r | |
711 | // ISA Bus Master.\r | |
712 | //\r | |
713 | // So we just return EFI_UNSUPPORTED for these functions.\r | |
714 | //\r | |
715 | if (!FeaturePcdGet (PcdIsaBusSupportIsaMemory)) {\r | |
716 | return EFI_UNSUPPORTED;\r | |
717 | }\r | |
718 | \r | |
719 | IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);\r | |
720 | \r | |
721 | //\r | |
722 | // Verify Isa IO Access\r | |
723 | //\r | |
724 | Status = IsaIoVerifyAccess (\r | |
725 | IsaIoDevice,\r | |
726 | IsaAccessTypeMem,\r | |
727 | Width,\r | |
728 | Count,\r | |
729 | &Offset\r | |
730 | );\r | |
731 | if (EFI_ERROR (Status)) {\r | |
732 | return Status;\r | |
733 | }\r | |
734 | //\r | |
735 | // Call PciIo->Mem.Write\r | |
736 | //\r | |
737 | Status = IsaIoDevice->PciIo->Mem.Write (\r | |
738 | IsaIoDevice->PciIo,\r | |
739 | (EFI_PCI_IO_PROTOCOL_WIDTH) Width,\r | |
740 | EFI_PCI_IO_PASS_THROUGH_BAR,\r | |
741 | Offset,\r | |
742 | Count,\r | |
743 | Buffer\r | |
744 | );\r | |
745 | \r | |
746 | if (EFI_ERROR (Status)) {\r | |
747 | ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r | |
748 | }\r | |
749 | \r | |
750 | return Status;\r | |
751 | }\r | |
752 | \r | |
753 | EFI_STATUS\r | |
754 | EFIAPI\r | |
755 | IsaIoCopyMem (\r | |
756 | IN EFI_ISA_IO_PROTOCOL *This,\r | |
757 | IN EFI_ISA_IO_PROTOCOL_WIDTH Width,\r | |
758 | IN UINT32 DestOffset,\r | |
759 | IN UINT32 SrcOffset,\r | |
760 | IN UINTN Count\r | |
761 | )\r | |
762 | /*++\r | |
763 | \r | |
764 | Routine Description:\r | |
765 | \r | |
766 | Performs an ISA I/O Copy Memory \r | |
767 | \r | |
768 | Arguments:\r | |
769 | \r | |
770 | This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r | |
771 | Width - Signifies the width of the memory copy operation.\r | |
772 | DestOffset - The offset of the destination \r | |
773 | SrcOffset - The offset of the source\r | |
774 | Count - The number of memory copy operations to perform\r | |
775 | \r | |
776 | Returns:\r | |
777 | \r | |
778 | EFI_SUCCESS - The data was copied sucessfully.\r | |
779 | EFI_UNSUPPORTED - The DestOffset or SrcOffset is not valid for this device.\r | |
780 | EFI_INVALID_PARAMETER - Width or Count, or both, were invalid.\r | |
781 | EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r | |
782 | \r | |
783 | --*/\r | |
784 | {\r | |
785 | EFI_STATUS Status;\r | |
786 | ISA_IO_DEVICE *IsaIoDevice;\r | |
787 | \r | |
788 | //\r | |
789 | // Set Feature Flag PcdIsaBusSupportBusMaster to FALSE to disable support for \r | |
790 | // ISA Bus Master.\r | |
791 | //\r | |
792 | // So we just return EFI_UNSUPPORTED for these functions.\r | |
793 | //\r | |
794 | if (!FeaturePcdGet (PcdIsaBusSupportIsaMemory)) {\r | |
795 | return EFI_UNSUPPORTED;\r | |
796 | }\r | |
797 | \r | |
798 | IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);\r | |
799 | \r | |
800 | //\r | |
801 | // Verify Isa IO Access for destination and source\r | |
802 | //\r | |
803 | Status = IsaIoVerifyAccess (\r | |
804 | IsaIoDevice,\r | |
805 | IsaAccessTypeMem,\r | |
806 | Width,\r | |
807 | Count,\r | |
808 | &DestOffset\r | |
809 | );\r | |
810 | if (EFI_ERROR (Status)) {\r | |
811 | return Status;\r | |
812 | }\r | |
813 | \r | |
814 | Status = IsaIoVerifyAccess (\r | |
815 | IsaIoDevice,\r | |
816 | IsaAccessTypeMem,\r | |
817 | Width,\r | |
818 | Count,\r | |
819 | &SrcOffset\r | |
820 | );\r | |
821 | if (EFI_ERROR (Status)) {\r | |
822 | return Status;\r | |
823 | }\r | |
824 | //\r | |
825 | // Call PciIo->CopyMem\r | |
826 | //\r | |
827 | Status = IsaIoDevice->PciIo->CopyMem (\r | |
828 | IsaIoDevice->PciIo,\r | |
829 | (EFI_PCI_IO_PROTOCOL_WIDTH) Width,\r | |
830 | EFI_PCI_IO_PASS_THROUGH_BAR,\r | |
831 | DestOffset,\r | |
832 | EFI_PCI_IO_PASS_THROUGH_BAR,\r | |
833 | SrcOffset,\r | |
834 | Count\r | |
835 | );\r | |
836 | \r | |
837 | if (EFI_ERROR (Status)) {\r | |
838 | ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r | |
839 | }\r | |
840 | \r | |
841 | return Status;\r | |
842 | }\r | |
843 | \r | |
844 | STATIC\r | |
845 | EFI_STATUS\r | |
846 | IsaIoMap_OnlySupportSlaveReadWrite (\r | |
847 | IN EFI_ISA_IO_PROTOCOL *This,\r | |
848 | IN EFI_ISA_IO_PROTOCOL_OPERATION Operation,\r | |
849 | IN UINT8 ChannelNumber OPTIONAL,\r | |
850 | IN UINT32 ChannelAttributes,\r | |
851 | IN VOID *HostAddress,\r | |
852 | IN OUT UINTN *NumberOfBytes,\r | |
853 | OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r | |
854 | OUT VOID **Mapping\r | |
855 | )\r | |
856 | /*++\r | |
857 | \r | |
858 | Routine Description:\r | |
859 | \r | |
860 | Maps a memory region for DMA, note this implementation\r | |
861 | only supports slave read/write operation to save code size.\r | |
862 | \r | |
863 | Arguments:\r | |
864 | \r | |
865 | This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r | |
866 | Operation - Indicates the type of DMA (slave or bus master), and if \r | |
867 | the DMA operation is going to read or write to system memory. \r | |
868 | ChannelNumber - The slave channel number to use for this DMA operation. \r | |
869 | If Operation and ChannelAttributes shows that this device \r | |
870 | performs bus mastering DMA, then this field is ignored. \r | |
871 | The legal range for this field is 0..7. \r | |
872 | ChannelAttributes - The attributes of the DMA channel to use for this DMA operation\r | |
873 | HostAddress - The system memory address to map to the device. \r | |
874 | NumberOfBytes - On input the number of bytes to map. On output the number \r | |
875 | of bytes that were mapped.\r | |
876 | DeviceAddress - The resulting map address for the bus master device to use \r | |
877 | to access the hosts HostAddress. \r | |
878 | Mapping - A resulting value to pass to EFI_ISA_IO.Unmap().\r | |
879 | \r | |
880 | Returns:\r | |
881 | \r | |
882 | EFI_SUCCESS - The range was mapped for the returned NumberOfBytes.\r | |
883 | EFI_INVALID_PARAMETER - The Operation or HostAddress is undefined.\r | |
884 | EFI_UNSUPPORTED - The HostAddress can not be mapped as a common buffer.\r | |
885 | EFI_DEVICE_ERROR - The system hardware could not map the requested address.\r | |
886 | EFI_OUT_OF_RESOURCES - The memory pages could not be allocated.\r | |
887 | \r | |
888 | --*/\r | |
889 | {\r | |
890 | EFI_STATUS Status;\r | |
891 | EFI_PHYSICAL_ADDRESS PhysicalAddress;\r | |
892 | ISA_MAP_INFO *IsaMapInfo;\r | |
893 | UINT8 DmaMode;\r | |
894 | UINTN MaxNumberOfBytes;\r | |
895 | UINT32 BaseAddress;\r | |
896 | UINT16 Count;\r | |
897 | \r | |
898 | UINT8 DmaMask;\r | |
899 | UINT8 DmaClear;\r | |
900 | UINT8 DmaChannelMode;\r | |
901 | \r | |
902 | if ((NULL == This) ||\r | |
903 | (NULL == HostAddress) ||\r | |
904 | (NULL == NumberOfBytes) ||\r | |
905 | (NULL == DeviceAddress) ||\r | |
906 | (NULL == Mapping)\r | |
907 | ) {\r | |
908 | return EFI_INVALID_PARAMETER;\r | |
909 | }\r | |
910 | \r | |
911 | \r | |
912 | //\r | |
913 | // Initialize the return values to their defaults\r | |
914 | //\r | |
915 | *Mapping = NULL;\r | |
916 | \r | |
917 | //\r | |
918 | // Make sure the Operation parameter is valid.\r | |
919 | // Light IsaIo only supports two operations.\r | |
920 | //\r | |
921 | if (!(Operation == EfiIsaIoOperationSlaveRead || \r | |
922 | Operation == EfiIsaIoOperationSlaveWrite)) {\r | |
923 | return EFI_INVALID_PARAMETER;\r | |
924 | }\r | |
925 | \r | |
926 | if (ChannelNumber >= 4) {\r | |
927 | //\r | |
928 | // The Light IsaIo doesn't support channelNumber larger than 4.\r | |
929 | //\r | |
930 | return EFI_INVALID_PARAMETER;\r | |
931 | }\r | |
932 | \r | |
933 | //\r | |
934 | // Map the HostAddress to a DeviceAddress.\r | |
935 | //\r | |
936 | PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress;\r | |
937 | if ((PhysicalAddress +*NumberOfBytes) > ISA_MAX_MEMORY_ADDRESS) {\r | |
938 | //\r | |
939 | // Common Buffer operations can not be remapped. If the common buffer\r | |
940 | // is above 16MB, then it is not possible to generate a mapping, so return\r | |
941 | // an error.\r | |
942 | //\r | |
943 | if (Operation == EfiIsaIoOperationBusMasterCommonBuffer) {\r | |
944 | return EFI_UNSUPPORTED;\r | |
945 | }\r | |
946 | //\r | |
947 | // Allocate an ISA_MAP_INFO structure to remember the mapping when Unmap()\r | |
948 | // is called later.\r | |
949 | //\r | |
950 | IsaMapInfo = AllocatePool (sizeof (ISA_MAP_INFO));\r | |
951 | if (IsaMapInfo == NULL) {\r | |
952 | *NumberOfBytes = 0;\r | |
953 | return EFI_OUT_OF_RESOURCES;\r | |
954 | }\r | |
955 | //\r | |
956 | // Return a pointer to the MAP_INFO structure in Mapping\r | |
957 | //\r | |
958 | *Mapping = IsaMapInfo;\r | |
959 | \r | |
960 | //\r | |
961 | // Initialize the MAP_INFO structure\r | |
962 | //\r | |
963 | IsaMapInfo->Operation = Operation;\r | |
964 | IsaMapInfo->NumberOfBytes = *NumberOfBytes;\r | |
965 | IsaMapInfo->NumberOfPages = EFI_SIZE_TO_PAGES (*NumberOfBytes);\r | |
966 | IsaMapInfo->HostAddress = PhysicalAddress;\r | |
967 | IsaMapInfo->MappedHostAddress = ISA_MAX_MEMORY_ADDRESS - 1;\r | |
968 | \r | |
969 | //\r | |
970 | // Allocate a buffer below 16MB to map the transfer to.\r | |
971 | //\r | |
972 | Status = gBS->AllocatePages (\r | |
973 | AllocateMaxAddress,\r | |
974 | EfiBootServicesData,\r | |
975 | IsaMapInfo->NumberOfPages,\r | |
976 | &IsaMapInfo->MappedHostAddress\r | |
977 | );\r | |
978 | if (EFI_ERROR (Status)) {\r | |
979 | gBS->FreePool (IsaMapInfo);\r | |
980 | *NumberOfBytes = 0;\r | |
981 | *Mapping = NULL;\r | |
982 | return Status;\r | |
983 | }\r | |
984 | //\r | |
985 | // If this is a read operation from the DMA agents's point of view,\r | |
986 | // then copy the contents of the real buffer into the mapped buffer\r | |
987 | // so the DMA agent can read the contents of the real buffer.\r | |
988 | //\r | |
989 | if (Operation == EfiIsaIoOperationSlaveRead) {\r | |
990 | CopyMem (\r | |
991 | (VOID *) (UINTN) IsaMapInfo->MappedHostAddress,\r | |
992 | (VOID *) (UINTN) IsaMapInfo->HostAddress,\r | |
993 | IsaMapInfo->NumberOfBytes\r | |
994 | );\r | |
995 | }\r | |
996 | //\r | |
997 | // The DeviceAddress is the address of the maped buffer below 16 MB\r | |
998 | //\r | |
999 | *DeviceAddress = IsaMapInfo->MappedHostAddress;\r | |
1000 | } else {\r | |
1001 | //\r | |
1002 | // The transfer is below 16 MB, so the DeviceAddress is simply the\r | |
1003 | // HostAddress\r | |
1004 | //\r | |
1005 | *DeviceAddress = PhysicalAddress;\r | |
1006 | }\r | |
1007 | \r | |
1008 | //\r | |
1009 | // Figure out what to program into the DMA Channel Mode Register\r | |
1010 | //\r | |
1011 | DmaMode = (UINT8) (B_8237_DMA_CHMODE_INCREMENT | (ChannelNumber & 0x03));\r | |
1012 | if (Operation == EfiIsaIoOperationSlaveRead) {\r | |
1013 | DmaMode |= V_8237_DMA_CHMODE_MEM2IO;\r | |
1014 | } else {\r | |
1015 | DmaMode |= V_8237_DMA_CHMODE_IO2MEM;\r | |
1016 | }\r | |
1017 | //\r | |
1018 | // We only support EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SINGLE_MODE in simplified IsaIo\r | |
1019 | //\r | |
1020 | DmaMode |= V_8237_DMA_CHMODE_SINGLE;\r | |
1021 | \r | |
1022 | //\r | |
1023 | // A Slave DMA transfer can not cross a 64K boundary.\r | |
1024 | // Compute *NumberOfBytes based on this restriction.\r | |
1025 | //\r | |
1026 | MaxNumberOfBytes = 0x10000 - ((UINT32) (*DeviceAddress) & 0xffff);\r | |
1027 | if (*NumberOfBytes > MaxNumberOfBytes) {\r | |
1028 | *NumberOfBytes = MaxNumberOfBytes;\r | |
1029 | }\r | |
1030 | //\r | |
1031 | // Compute the values to program into the BaseAddress and Count registers\r | |
1032 | // of the Slave DMA controller\r | |
1033 | //\r | |
1034 | BaseAddress = (UINT32) (*DeviceAddress);\r | |
1035 | Count = (UINT16) (*NumberOfBytes - 1);\r | |
1036 | //\r | |
1037 | // Program the DMA Write Single Mask Register for ChannelNumber\r | |
1038 | // Clear the DMA Byte Pointer Register\r | |
1039 | //\r | |
1040 | DmaMask = R_8237_DMA_WRSMSK_CH0_3;\r | |
1041 | DmaClear = R_8237_DMA_CBPR_CH0_3;\r | |
1042 | DmaChannelMode = R_8237_DMA_CHMODE_CH0_3;\r | |
1043 | \r | |
1044 | Status = WritePort (\r | |
1045 | This,\r | |
1046 | DmaMask,\r | |
1047 | (UINT8) (B_8237_DMA_WRSMSK_CMS | (ChannelNumber & 0x03))\r | |
1048 | );\r | |
1049 | if (EFI_ERROR (Status)) {\r | |
1050 | return Status;\r | |
1051 | }\r | |
1052 | \r | |
1053 | Status = WritePort (\r | |
1054 | This,\r | |
1055 | DmaClear,\r | |
1056 | (UINT8) (B_8237_DMA_WRSMSK_CMS | (ChannelNumber & 0x03))\r | |
1057 | );\r | |
1058 | if (EFI_ERROR (Status)) {\r | |
1059 | return Status;\r | |
1060 | }\r | |
1061 | \r | |
1062 | Status = WritePort (This, DmaChannelMode, DmaMode);\r | |
1063 | if (EFI_ERROR (Status)) {\r | |
1064 | return Status;\r | |
1065 | }\r | |
1066 | \r | |
1067 | Status = WriteDmaPort (\r | |
1068 | This,\r | |
1069 | DmaRegisters[ChannelNumber].Address,\r | |
1070 | DmaRegisters[ChannelNumber].Page,\r | |
1071 | DmaRegisters[ChannelNumber].Count,\r | |
1072 | BaseAddress,\r | |
1073 | Count\r | |
1074 | );\r | |
1075 | if (EFI_ERROR (Status)) {\r | |
1076 | return Status;\r | |
1077 | }\r | |
1078 | \r | |
1079 | Status = WritePort (\r | |
1080 | This,\r | |
1081 | DmaMask,\r | |
1082 | (UINT8) (ChannelNumber & 0x03)\r | |
1083 | );\r | |
1084 | if (EFI_ERROR (Status)) {\r | |
1085 | return Status;\r | |
1086 | }\r | |
1087 | \r | |
1088 | return EFI_SUCCESS;\r | |
1089 | }\r | |
1090 | \r | |
1091 | STATIC\r | |
1092 | EFI_STATUS\r | |
1093 | IsaIoMap_FullSupport (\r | |
1094 | IN EFI_ISA_IO_PROTOCOL *This,\r | |
1095 | IN EFI_ISA_IO_PROTOCOL_OPERATION Operation,\r | |
1096 | IN UINT8 ChannelNumber OPTIONAL,\r | |
1097 | IN UINT32 ChannelAttributes,\r | |
1098 | IN VOID *HostAddress,\r | |
1099 | IN OUT UINTN *NumberOfBytes,\r | |
1100 | OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r | |
1101 | OUT VOID **Mapping\r | |
1102 | )\r | |
1103 | /*++\r | |
1104 | \r | |
1105 | Routine Description:\r | |
1106 | \r | |
1107 | Maps a memory region for DMA. This implementation implement the \r | |
1108 | the full mapping support.\r | |
1109 | \r | |
1110 | Arguments:\r | |
1111 | \r | |
1112 | This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r | |
1113 | Operation - Indicates the type of DMA (slave or bus master), and if \r | |
1114 | the DMA operation is going to read or write to system memory. \r | |
1115 | ChannelNumber - The slave channel number to use for this DMA operation. \r | |
1116 | If Operation and ChannelAttributes shows that this device \r | |
1117 | performs bus mastering DMA, then this field is ignored. \r | |
1118 | The legal range for this field is 0..7. \r | |
1119 | ChannelAttributes - The attributes of the DMA channel to use for this DMA operation\r | |
1120 | HostAddress - The system memory address to map to the device. \r | |
1121 | NumberOfBytes - On input the number of bytes to map. On output the number \r | |
1122 | of bytes that were mapped.\r | |
1123 | DeviceAddress - The resulting map address for the bus master device to use \r | |
1124 | - to access the hosts HostAddress. \r | |
1125 | Mapping - A resulting value to pass to EFI_ISA_IO.Unmap().\r | |
1126 | \r | |
1127 | Returns:\r | |
1128 | \r | |
1129 | EFI_SUCCESS - The range was mapped for the returned NumberOfBytes.\r | |
1130 | EFI_INVALID_PARAMETER - The Operation or HostAddress is undefined.\r | |
1131 | EFI_UNSUPPORTED - The HostAddress can not be mapped as a common buffer.\r | |
1132 | EFI_DEVICE_ERROR - The system hardware could not map the requested address.\r | |
1133 | EFI_OUT_OF_RESOURCES - The memory pages could not be allocated.\r | |
1134 | \r | |
1135 | --*/\r | |
1136 | {\r | |
1137 | EFI_STATUS Status;\r | |
1138 | BOOLEAN Master;\r | |
1139 | BOOLEAN Read;\r | |
1140 | EFI_PHYSICAL_ADDRESS PhysicalAddress;\r | |
1141 | ISA_MAP_INFO *IsaMapInfo;\r | |
1142 | UINT8 DmaMode;\r | |
1143 | UINTN MaxNumberOfBytes;\r | |
1144 | UINT32 BaseAddress;\r | |
1145 | UINT16 Count;\r | |
1146 | \r | |
1147 | UINT8 DmaMask;\r | |
1148 | UINT8 DmaClear;\r | |
1149 | UINT8 DmaChannelMode;\r | |
1150 | \r | |
1151 | if ((NULL == This) ||\r | |
1152 | (NULL == HostAddress) ||\r | |
1153 | (NULL == NumberOfBytes) ||\r | |
1154 | (NULL == DeviceAddress) ||\r | |
1155 | (NULL == Mapping)\r | |
1156 | ) {\r | |
1157 | return EFI_INVALID_PARAMETER;\r | |
1158 | }\r | |
1159 | \r | |
1160 | \r | |
1161 | //\r | |
1162 | // Initialize the return values to their defaults\r | |
1163 | //\r | |
1164 | *Mapping = NULL;\r | |
1165 | \r | |
1166 | //\r | |
1167 | // Make sure the Operation parameter is valid\r | |
1168 | //\r | |
1169 | if (Operation < 0 || Operation >= EfiIsaIoOperationMaximum) {\r | |
1170 | return EFI_INVALID_PARAMETER;\r | |
1171 | }\r | |
1172 | //\r | |
1173 | // See if this is a Slave DMA Operation\r | |
1174 | //\r | |
1175 | Master = TRUE;\r | |
1176 | Read = FALSE;\r | |
1177 | if (Operation == EfiIsaIoOperationSlaveRead) {\r | |
1178 | Operation = EfiIsaIoOperationBusMasterRead;\r | |
1179 | Master = FALSE;\r | |
1180 | Read = TRUE;\r | |
1181 | }\r | |
1182 | \r | |
1183 | if (Operation == EfiIsaIoOperationSlaveWrite) {\r | |
1184 | Operation = EfiIsaIoOperationBusMasterWrite;\r | |
1185 | Master = FALSE;\r | |
1186 | Read = FALSE;\r | |
1187 | }\r | |
1188 | \r | |
1189 | if (!Master) {\r | |
1190 | //\r | |
1191 | // Make sure that ChannelNumber is a valid channel number\r | |
1192 | // Channel 4 is used to cascade, so it is illegal.\r | |
1193 | //\r | |
1194 | if (ChannelNumber == 4 || ChannelNumber > 7) {\r | |
1195 | return EFI_INVALID_PARAMETER;\r | |
1196 | }\r | |
1197 | //\r | |
1198 | // This implementation only support COMPATIBLE DMA Transfers\r | |
1199 | //\r | |
1200 | if (!(ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_COMPATIBLE)) {\r | |
1201 | return EFI_INVALID_PARAMETER;\r | |
1202 | }\r | |
1203 | \r | |
1204 | if (ChannelAttributes &\r | |
1205 | (\r | |
1206 | EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_A |\r | |
1207 | EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_B |\r | |
1208 | EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_C\r | |
1209 | )\r | |
1210 | ) {\r | |
1211 | return EFI_INVALID_PARAMETER;\r | |
1212 | }\r | |
1213 | \r | |
1214 | if (ChannelNumber < 4) {\r | |
1215 | //\r | |
1216 | // If this is Channel 0..3, then the width must be 8 bit\r | |
1217 | //\r | |
1218 | if (!(ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_8) ||\r | |
1219 | (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_16)\r | |
1220 | ) {\r | |
1221 | return EFI_INVALID_PARAMETER;\r | |
1222 | }\r | |
1223 | } else {\r | |
1224 | //\r | |
1225 | // If this is Channel 4..7, then the width must be 16 bit\r | |
1226 | //\r | |
1227 | if ((ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_8) ||\r | |
1228 | (!(ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_16))\r | |
1229 | ) {\r | |
1230 | return EFI_INVALID_PARAMETER;\r | |
1231 | }\r | |
1232 | }\r | |
1233 | //\r | |
1234 | // Either Demand Mode or Single Mode must be selected, but not both\r | |
1235 | //\r | |
1236 | if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SINGLE_MODE) {\r | |
1237 | if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_DEMAND_MODE) {\r | |
1238 | return EFI_INVALID_PARAMETER;\r | |
1239 | }\r | |
1240 | } else {\r | |
1241 | if (!(ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_DEMAND_MODE)) {\r | |
1242 | return EFI_INVALID_PARAMETER;\r | |
1243 | }\r | |
1244 | }\r | |
1245 | }\r | |
1246 | //\r | |
1247 | // Map the HostAddress to a DeviceAddress.\r | |
1248 | //\r | |
1249 | PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress;\r | |
1250 | if ((PhysicalAddress +*NumberOfBytes) > ISA_MAX_MEMORY_ADDRESS) {\r | |
1251 | //\r | |
1252 | // Common Buffer operations can not be remapped. If the common buffer\r | |
1253 | // is above 16MB, then it is not possible to generate a mapping, so return\r | |
1254 | // an error.\r | |
1255 | //\r | |
1256 | if (Operation == EfiIsaIoOperationBusMasterCommonBuffer) {\r | |
1257 | return EFI_UNSUPPORTED;\r | |
1258 | }\r | |
1259 | //\r | |
1260 | // Allocate an ISA_MAP_INFO structure to remember the mapping when Unmap()\r | |
1261 | // is called later.\r | |
1262 | //\r | |
1263 | IsaMapInfo = AllocatePool (sizeof (ISA_MAP_INFO));\r | |
1264 | if (IsaMapInfo == NULL) {\r | |
1265 | *NumberOfBytes = 0;\r | |
1266 | return EFI_OUT_OF_RESOURCES;\r | |
1267 | }\r | |
1268 | //\r | |
1269 | // Return a pointer to the MAP_INFO structure in Mapping\r | |
1270 | //\r | |
1271 | *Mapping = IsaMapInfo;\r | |
1272 | \r | |
1273 | //\r | |
1274 | // Initialize the MAP_INFO structure\r | |
1275 | //\r | |
1276 | IsaMapInfo->Operation = Operation;\r | |
1277 | IsaMapInfo->NumberOfBytes = *NumberOfBytes;\r | |
1278 | IsaMapInfo->NumberOfPages = EFI_SIZE_TO_PAGES (*NumberOfBytes);\r | |
1279 | IsaMapInfo->HostAddress = PhysicalAddress;\r | |
1280 | IsaMapInfo->MappedHostAddress = ISA_MAX_MEMORY_ADDRESS - 1;\r | |
1281 | \r | |
1282 | //\r | |
1283 | // Allocate a buffer below 16MB to map the transfer to.\r | |
1284 | //\r | |
1285 | Status = gBS->AllocatePages (\r | |
1286 | AllocateMaxAddress,\r | |
1287 | EfiBootServicesData,\r | |
1288 | IsaMapInfo->NumberOfPages,\r | |
1289 | &IsaMapInfo->MappedHostAddress\r | |
1290 | );\r | |
1291 | if (EFI_ERROR (Status)) {\r | |
1292 | gBS->FreePool (IsaMapInfo);\r | |
1293 | *NumberOfBytes = 0;\r | |
1294 | *Mapping = NULL;\r | |
1295 | return Status;\r | |
1296 | }\r | |
1297 | //\r | |
1298 | // If this is a read operation from the DMA agents's point of view,\r | |
1299 | // then copy the contents of the real buffer into the mapped buffer\r | |
1300 | // so the DMA agent can read the contents of the real buffer.\r | |
1301 | //\r | |
1302 | if (Operation == EfiIsaIoOperationBusMasterRead) {\r | |
1303 | CopyMem (\r | |
1304 | (VOID *) (UINTN) IsaMapInfo->MappedHostAddress,\r | |
1305 | (VOID *) (UINTN) IsaMapInfo->HostAddress,\r | |
1306 | IsaMapInfo->NumberOfBytes\r | |
1307 | );\r | |
1308 | }\r | |
1309 | //\r | |
1310 | // The DeviceAddress is the address of the maped buffer below 16 MB\r | |
1311 | //\r | |
1312 | *DeviceAddress = IsaMapInfo->MappedHostAddress;\r | |
1313 | } else {\r | |
1314 | //\r | |
1315 | // The transfer is below 16 MB, so the DeviceAddress is simply the\r | |
1316 | // HostAddress\r | |
1317 | //\r | |
1318 | *DeviceAddress = PhysicalAddress;\r | |
1319 | }\r | |
1320 | //\r | |
1321 | // If this is a Bus Master operation then return\r | |
1322 | //\r | |
1323 | if (Master) {\r | |
1324 | return EFI_SUCCESS;\r | |
1325 | }\r | |
1326 | //\r | |
1327 | // Figure out what to program into the DMA Channel Mode Register\r | |
1328 | //\r | |
1329 | DmaMode = (UINT8) (B_8237_DMA_CHMODE_INCREMENT | (ChannelNumber & 0x03));\r | |
1330 | if (Read) {\r | |
1331 | DmaMode |= V_8237_DMA_CHMODE_MEM2IO;\r | |
1332 | } else {\r | |
1333 | DmaMode |= V_8237_DMA_CHMODE_IO2MEM;\r | |
1334 | }\r | |
1335 | \r | |
1336 | if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_AUTO_INITIALIZE) {\r | |
1337 | DmaMode |= B_8237_DMA_CHMODE_AE;\r | |
1338 | }\r | |
1339 | \r | |
1340 | if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_DEMAND_MODE) {\r | |
1341 | DmaMode |= V_8237_DMA_CHMODE_DEMAND;\r | |
1342 | }\r | |
1343 | \r | |
1344 | if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SINGLE_MODE) {\r | |
1345 | DmaMode |= V_8237_DMA_CHMODE_SINGLE;\r | |
1346 | }\r | |
1347 | //\r | |
1348 | // A Slave DMA transfer can not cross a 64K boundary.\r | |
1349 | // Compute *NumberOfBytes based on this restriction.\r | |
1350 | //\r | |
1351 | MaxNumberOfBytes = 0x10000 - ((UINT32) (*DeviceAddress) & 0xffff);\r | |
1352 | if (*NumberOfBytes > MaxNumberOfBytes) {\r | |
1353 | *NumberOfBytes = MaxNumberOfBytes;\r | |
1354 | }\r | |
1355 | //\r | |
1356 | // Compute the values to program into the BaseAddress and Count registers\r | |
1357 | // of the Slave DMA controller\r | |
1358 | //\r | |
1359 | if (ChannelNumber < 4) {\r | |
1360 | BaseAddress = (UINT32) (*DeviceAddress);\r | |
1361 | Count = (UINT16) (*NumberOfBytes - 1);\r | |
1362 | } else {\r | |
1363 | BaseAddress = (UINT32) (((UINT32) (*DeviceAddress) & 0xff0000) | (((UINT32) (*DeviceAddress) & 0xffff) >> 1));\r | |
1364 | Count = (UINT16) ((*NumberOfBytes - 1) >> 1);\r | |
1365 | }\r | |
1366 | //\r | |
1367 | // Program the DMA Write Single Mask Register for ChannelNumber\r | |
1368 | // Clear the DMA Byte Pointer Register\r | |
1369 | //\r | |
1370 | if (ChannelNumber < 4) {\r | |
1371 | DmaMask = R_8237_DMA_WRSMSK_CH0_3;\r | |
1372 | DmaClear = R_8237_DMA_CBPR_CH0_3;\r | |
1373 | DmaChannelMode = R_8237_DMA_CHMODE_CH0_3;\r | |
1374 | } else {\r | |
1375 | DmaMask = R_8237_DMA_WRSMSK_CH4_7;\r | |
1376 | DmaClear = R_8237_DMA_CBPR_CH4_7;\r | |
1377 | DmaChannelMode = R_8237_DMA_CHMODE_CH4_7;\r | |
1378 | }\r | |
1379 | \r | |
1380 | Status = WritePort (\r | |
1381 | This,\r | |
1382 | DmaMask,\r | |
1383 | (UINT8) (B_8237_DMA_WRSMSK_CMS | (ChannelNumber & 0x03))\r | |
1384 | );\r | |
1385 | if (EFI_ERROR (Status)) {\r | |
1386 | return Status;\r | |
1387 | }\r | |
1388 | \r | |
1389 | Status = WritePort (\r | |
1390 | This,\r | |
1391 | DmaClear,\r | |
1392 | (UINT8) (B_8237_DMA_WRSMSK_CMS | (ChannelNumber & 0x03))\r | |
1393 | );\r | |
1394 | if (EFI_ERROR (Status)) {\r | |
1395 | return Status;\r | |
1396 | }\r | |
1397 | \r | |
1398 | Status = WritePort (This, DmaChannelMode, DmaMode);\r | |
1399 | if (EFI_ERROR (Status)) {\r | |
1400 | return Status;\r | |
1401 | }\r | |
1402 | \r | |
1403 | Status = WriteDmaPort (\r | |
1404 | This,\r | |
1405 | DmaRegisters[ChannelNumber].Address,\r | |
1406 | DmaRegisters[ChannelNumber].Page,\r | |
1407 | DmaRegisters[ChannelNumber].Count,\r | |
1408 | BaseAddress,\r | |
1409 | Count\r | |
1410 | );\r | |
1411 | if (EFI_ERROR (Status)) {\r | |
1412 | return Status;\r | |
1413 | }\r | |
1414 | \r | |
1415 | Status = WritePort (\r | |
1416 | This,\r | |
1417 | DmaMask,\r | |
1418 | (UINT8) (ChannelNumber & 0x03)\r | |
1419 | );\r | |
1420 | if (EFI_ERROR (Status)) {\r | |
1421 | return Status;\r | |
1422 | }\r | |
1423 | \r | |
1424 | return EFI_SUCCESS;\r | |
1425 | }\r | |
1426 | \r | |
1427 | EFI_STATUS\r | |
1428 | EFIAPI\r | |
1429 | IsaIoMap (\r | |
1430 | IN EFI_ISA_IO_PROTOCOL *This,\r | |
1431 | IN EFI_ISA_IO_PROTOCOL_OPERATION Operation,\r | |
1432 | IN UINT8 ChannelNumber OPTIONAL,\r | |
1433 | IN UINT32 ChannelAttributes,\r | |
1434 | IN VOID *HostAddress,\r | |
1435 | IN OUT UINTN *NumberOfBytes,\r | |
1436 | OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r | |
1437 | OUT VOID **Mapping\r | |
1438 | )\r | |
1439 | /*++\r | |
1440 | \r | |
1441 | Routine Description:\r | |
1442 | \r | |
1443 | Maps a memory region for DMA\r | |
1444 | \r | |
1445 | Arguments:\r | |
1446 | \r | |
1447 | This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r | |
1448 | Operation - Indicates the type of DMA (slave or bus master), and if \r | |
1449 | the DMA operation is going to read or write to system memory. \r | |
1450 | ChannelNumber - The slave channel number to use for this DMA operation. \r | |
1451 | If Operation and ChannelAttributes shows that this device \r | |
1452 | performs bus mastering DMA, then this field is ignored. \r | |
1453 | The legal range for this field is 0..7. \r | |
1454 | ChannelAttributes - The attributes of the DMA channel to use for this DMA operation\r | |
1455 | HostAddress - The system memory address to map to the device. \r | |
1456 | NumberOfBytes - On input the number of bytes to map. On output the number \r | |
1457 | of bytes that were mapped.\r | |
1458 | DeviceAddress - The resulting map address for the bus master device to use \r | |
1459 | - to access the hosts HostAddress. \r | |
1460 | Mapping - A resulting value to pass to EFI_ISA_IO.Unmap().\r | |
1461 | \r | |
1462 | Returns:\r | |
1463 | \r | |
1464 | EFI_SUCCESS - The range was mapped for the returned NumberOfBytes.\r | |
1465 | EFI_INVALID_PARAMETER - The Operation or HostAddress is undefined.\r | |
1466 | EFI_UNSUPPORTED - The HostAddress can not be mapped as a common buffer.\r | |
1467 | EFI_DEVICE_ERROR - The system hardware could not map the requested address.\r | |
1468 | EFI_OUT_OF_RESOURCES - The memory pages could not be allocated.\r | |
1469 | \r | |
1470 | --*/\r | |
1471 | {\r | |
1472 | //\r | |
1473 | // Or unset Feature Flag PcdIsaBusSupportDma to disable support for ISA DMA.\r | |
1474 | //\r | |
1475 | if (!FeaturePcdGet (PcdIsaBusSupportDma)) {\r | |
1476 | return EFI_UNSUPPORTED;\r | |
1477 | }\r | |
1478 | //\r | |
1479 | // Set Feature Flag PcdIsaBusSupportBusMaster to FALSE to disable support for \r | |
1480 | // ISA Bus Master.\r | |
1481 | //\r | |
1482 | // So we just return EFI_UNSUPPORTED for these functions.\r | |
1483 | //\r | |
1484 | if (FeaturePcdGet (PcdIsaBusOnlySupportSlaveDma)) {\r | |
1485 | return IsaIoMap_OnlySupportSlaveReadWrite (\r | |
1486 | This,\r | |
1487 | Operation,\r | |
1488 | ChannelNumber,\r | |
1489 | ChannelAttributes,\r | |
1490 | HostAddress,\r | |
1491 | NumberOfBytes,\r | |
1492 | DeviceAddress,\r | |
1493 | Mapping\r | |
1494 | );\r | |
1495 | \r | |
1496 | } else {\r | |
1497 | return IsaIoMap_FullSupport (\r | |
1498 | This,\r | |
1499 | Operation,\r | |
1500 | ChannelNumber,\r | |
1501 | ChannelAttributes,\r | |
1502 | HostAddress,\r | |
1503 | NumberOfBytes,\r | |
1504 | DeviceAddress,\r | |
1505 | Mapping\r | |
1506 | );\r | |
1507 | }\r | |
1508 | }\r | |
1509 | EFI_STATUS\r | |
1510 | EFIAPI\r | |
1511 | IsaIoAllocateBuffer (\r | |
1512 | IN EFI_ISA_IO_PROTOCOL *This,\r | |
1513 | IN EFI_ALLOCATE_TYPE Type,\r | |
1514 | IN EFI_MEMORY_TYPE MemoryType,\r | |
1515 | IN UINTN Pages,\r | |
1516 | OUT VOID **HostAddress,\r | |
1517 | IN UINT64 Attributes\r | |
1518 | )\r | |
1519 | /*++\r | |
1520 | \r | |
1521 | Routine Description:\r | |
1522 | \r | |
1523 | Allocates a common buffer for DMA\r | |
1524 | \r | |
1525 | Arguments:\r | |
1526 | \r | |
1527 | This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r | |
1528 | Type - The type allocation to perform.\r | |
1529 | MemoryType - The type of memory to allocate.\r | |
1530 | Pages - The number of pages to allocate.\r | |
1531 | HostAddress - A pointer to store the base address of the allocated range.\r | |
1532 | Attributes - The requested bit mask of attributes for the allocated range.\r | |
1533 | \r | |
1534 | Returns:\r | |
1535 | \r | |
1536 | EFI_SUCCESS - The requested memory pages were allocated.\r | |
1537 | EFI_INVALID_PARAMETER - Type is invalid or MemoryType is invalid or HostAddress is NULL\r | |
1538 | EFI_UNSUPPORTED - Attributes is unsupported or the memory range specified \r | |
1539 | by HostAddress, Pages, and Type is not available for common buffer use.\r | |
1540 | EFI_OUT_OF_RESOURCES - The memory pages could not be allocated.\r | |
1541 | \r | |
1542 | --*/\r | |
1543 | {\r | |
1544 | EFI_STATUS Status;\r | |
1545 | EFI_PHYSICAL_ADDRESS PhysicalAddress;\r | |
1546 | \r | |
1547 | //\r | |
1548 | // Set Feature Flag PcdIsaBusOnlySupportSlaveDma to FALSE to disable support for \r | |
1549 | // ISA Bus Master.\r | |
1550 | // Or unset Feature Flag PcdIsaBusSupportDma to disable support for ISA DMA.\r | |
1551 | //\r | |
1552 | if (!FeaturePcdGet (PcdIsaBusSupportDma) || FeaturePcdGet (PcdIsaBusOnlySupportSlaveDma)) {\r | |
1553 | return EFI_UNSUPPORTED;\r | |
1554 | }\r | |
1555 | \r | |
1556 | if (HostAddress == NULL) {\r | |
1557 | return EFI_INVALID_PARAMETER;\r | |
1558 | }\r | |
1559 | \r | |
1560 | if (Type < AllocateAnyPages || Type >= MaxAllocateType) {\r | |
1561 | return EFI_INVALID_PARAMETER;\r | |
1562 | }\r | |
1563 | //\r | |
1564 | // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData\r | |
1565 | //\r | |
1566 | if (MemoryType != EfiBootServicesData && MemoryType != EfiRuntimeServicesData) {\r | |
1567 | return EFI_INVALID_PARAMETER;\r | |
1568 | }\r | |
1569 | \r | |
1570 | if (Attributes &~(EFI_ISA_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE | EFI_ISA_IO_ATTRIBUTE_MEMORY_CACHED)) {\r | |
1571 | return EFI_UNSUPPORTED;\r | |
1572 | }\r | |
1573 | \r | |
1574 | PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) (ISA_MAX_MEMORY_ADDRESS - 1);\r | |
1575 | if (Type == AllocateAddress) {\r | |
1576 | if ((UINTN) (*HostAddress) >= ISA_MAX_MEMORY_ADDRESS) {\r | |
1577 | return EFI_UNSUPPORTED;\r | |
1578 | } else {\r | |
1579 | PhysicalAddress = (UINTN) (*HostAddress);\r | |
1580 | }\r | |
1581 | }\r | |
1582 | \r | |
1583 | if (Type == AllocateAnyPages) {\r | |
1584 | Type = AllocateMaxAddress;\r | |
1585 | }\r | |
1586 | \r | |
1587 | Status = gBS->AllocatePages (Type, MemoryType, Pages, &PhysicalAddress);\r | |
1588 | if (EFI_ERROR (Status)) {\r | |
1589 | ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r | |
1590 | return Status;\r | |
1591 | }\r | |
1592 | \r | |
1593 | *HostAddress = (VOID *) (UINTN) PhysicalAddress;\r | |
1594 | return Status;\r | |
1595 | }\r | |
1596 | \r | |
1597 | EFI_STATUS\r | |
1598 | EFIAPI\r | |
1599 | IsaIoFreeBuffer (\r | |
1600 | IN EFI_ISA_IO_PROTOCOL *This,\r | |
1601 | IN UINTN Pages,\r | |
1602 | IN VOID *HostAddress\r | |
1603 | )\r | |
1604 | /*++\r | |
1605 | \r | |
1606 | Routine Description:\r | |
1607 | \r | |
1608 | Frees a common buffer \r | |
1609 | \r | |
1610 | Arguments:\r | |
1611 | \r | |
1612 | This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r | |
1613 | Pages - The number of pages to free.\r | |
1614 | HostAddress - The base address of the allocated range.\r | |
1615 | \r | |
1616 | Returns:\r | |
1617 | \r | |
1618 | EFI_SUCCESS - The requested memory pages were freed.\r | |
1619 | EFI_INVALID_PARAMETER - The memory was not allocated with EFI_ISA_IO.AllocateBufer().\r | |
1620 | \r | |
1621 | --*/\r | |
1622 | {\r | |
1623 | EFI_STATUS Status;\r | |
1624 | EFI_PHYSICAL_ADDRESS PhysicalAddress;\r | |
1625 | \r | |
1626 | //\r | |
1627 | // Set Feature Flag PcdIsaBusOnlySupportSlaveDma to FALSE to disable support for \r | |
1628 | // ISA Bus Master.\r | |
1629 | // Or unset Feature Flag PcdIsaBusSupportDma to disable support for ISA DMA.\r | |
1630 | //\r | |
1631 | if (!FeaturePcdGet (PcdIsaBusSupportDma) || FeaturePcdGet (PcdIsaBusOnlySupportSlaveDma)) {\r | |
1632 | return EFI_UNSUPPORTED;\r | |
1633 | }\r | |
1634 | \r | |
1635 | PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress;\r | |
1636 | Status = gBS->FreePages (\r | |
1637 | PhysicalAddress,\r | |
1638 | Pages\r | |
1639 | );\r | |
1640 | if (EFI_ERROR (Status)) {\r | |
1641 | ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r | |
1642 | }\r | |
1643 | \r | |
1644 | return Status;\r | |
1645 | }\r | |
1646 | \r |