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