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