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