4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync The implementation for EFI_ISA_IO_PROTOCOL.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncCopyright (c) 2010, Intel Corporation. All rights reserved.<BR>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncThis program and the accompanying materials
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncare licensed and made available under the terms and conditions of the BSD License
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncwhich accompanies this distribution. The full text of the license may be found at
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncTHE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncWITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync// Module Variables
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync }, // Channel 4 is invalid
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Verifies access to an ISA device
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] IsaIoDevice The ISA device to be verified.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Type The Access type. The input must be either IsaAccessTypeMem or IsaAccessTypeIo.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Width The width of the memory operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Count The number of memory operations to perform.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Offset The offset in ISA memory space to start the memory operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS Verify success.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_UNSUPPORTED The device ont support the access type.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If Width is EfiIsaIoWidthFifoUintX then convert to EfiIsaIoWidthUintX
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If Width is EfiIsaIoWidthFillUintX then convert to EfiIsaIoWidthUintX
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (Width >= EfiIsaIoWidthFifoUint8 && Width < EfiIsaIoWidthFifoReserved) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Width = (EFI_ISA_IO_PROTOCOL_WIDTH) (Width & 0x03);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Item = IsaIoDevice->IsaIo.ResourceList->ResourceItem;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync while (Item->Type != EfiIsaAcpiResourceEndOfList) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((Type == IsaAccessTypeMem && Item->Type == EfiIsaAcpiResourceMemory) ||
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync (Type == IsaAccessTypeIo && Item->Type == EfiIsaAcpiResourceIo)) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (Offset >= Item->StartRange && (Offset + Count * (UINT32)(1 << Width)) - 1 <= Item->EndRange) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (Offset >= Item->StartRange && Offset <= Item->EndRange) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Convert the IO Information in ACPI descriptor to IO ISA Attribute.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Information The IO Information in ACPI descriptor
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @return UINT32 The IO ISA Attribute
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Convert the IRQ Information in ACPI descriptor to IRQ ISA Attribute.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Information The IRQ Information in ACPI descriptor
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @return UINT32 The IRQ ISA Attribute
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((Information & EFI_ACPI_IRQ_POLARITY_MASK) == EFI_ACPI_IRQ_HIGH_TRUE) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((Information & EFI_ACPI_IRQ_MODE) == EFI_ACPI_IRQ_LEVEL_TRIGGERED) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Attribute = EFI_ISA_ACPI_IRQ_TYPE_HIGH_TRUE_LEVEL_SENSITIVE;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Attribute = EFI_ISA_ACPI_IRQ_TYPE_HIGH_TRUE_EDGE_SENSITIVE;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((Information & EFI_ACPI_IRQ_MODE) == EFI_ACPI_IRQ_LEVEL_TRIGGERED) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Attribute = EFI_ISA_ACPI_IRQ_TYPE_LOW_TRUE_LEVEL_SENSITIVE;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Attribute = EFI_ISA_ACPI_IRQ_TYPE_LOW_TRUE_EDGE_SENSITIVE;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Convert the Memory Information in ACPI descriptor to Memory ISA Attribute.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Information The Memory Information in ACPI descriptor
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @return UINT32 The Memory ISA Attribute
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync switch (Information & EFI_ACPI_MEMORY_WRITE_STATUS_MASK) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Convert the DMA Information in ACPI descriptor to DMA ISA Attribute.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Information The DMA Information in ACPI descriptor
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @return UINT32 The DMA ISA Attribute
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Attribute = EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SINGLE_MODE;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync switch (Information & EFI_ACPI_DMA_SPEED_TYPE_MASK) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Attribute |= EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_COMPATIBLE;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Attribute |= EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_A;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Attribute |= EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_B;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Attribute |= EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_C;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync switch (Information & EFI_ACPI_DMA_TRANSFER_TYPE_MASK) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Attribute |= EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_8;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Attribute |= EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_16;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Convert the ACPI resource descriptor to ISA resource descriptor.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] AcpiResource Pointer to the ACPI resource descriptor
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[out] IsaResource The optional pointer to the buffer to
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync store the converted ISA resource descriptor
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @return UINTN Number of ISA resource descriptor needed
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync EFI_ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR *FixedIo;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync EFI_ACPI_32_BIT_FIXED_MEMORY_RANGE_DESCRIPTOR *FixedMemory;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Dma = (EFI_ACPI_DMA_DESCRIPTOR *) AcpiResource.SmallHeader;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync for (Index = 0; Index < sizeof (Dma->ChannelMask) * 8; Index++) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].Attribute = IsaDmaAttribute (Dma->Information);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Io = (EFI_ACPI_IO_PORT_DESCRIPTOR *) AcpiResource.SmallHeader;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].Attribute = IsaIoAttribute (Io->Information);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].StartRange = Io->BaseAddressMin;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].EndRange = Io->BaseAddressMin + Io->Length - 1;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync FixedIo = (EFI_ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR *) AcpiResource.SmallHeader;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].Attribute = EFI_ISA_ACPI_IO_DECODE_10_BITS;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].StartRange = FixedIo->BaseAddress;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].EndRange = FixedIo->BaseAddress + FixedIo->Length - 1;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Irq = (EFI_ACPI_IRQ_DESCRIPTOR *) AcpiResource.SmallHeader;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync for (Index = 0; Index < sizeof (Irq->Mask) * 8; Index++) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].Type = EfiIsaAcpiResourceInterrupt;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (AcpiResource.SmallHeader->Byte == ACPI_IRQ_DESCRIPTOR) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].Attribute = IsaIrqAttribute (Irq->Information);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].Attribute = EFI_ISA_ACPI_IRQ_TYPE_HIGH_TRUE_EDGE_SENSITIVE;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Memory = (EFI_ACPI_32_BIT_MEMORY_RANGE_DESCRIPTOR *) AcpiResource.LargeHeader;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].Type = EfiIsaAcpiResourceMemory;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].Attribute = IsaMemoryAttribute (Memory->Information);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].StartRange = Memory->BaseAddressMin;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].EndRange = Memory->BaseAddressMin + Memory->Length - 1;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync FixedMemory = (EFI_ACPI_32_BIT_FIXED_MEMORY_RANGE_DESCRIPTOR *) AcpiResource.LargeHeader;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].Type = EfiIsaAcpiResourceMemory;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].Attribute = IsaMemoryAttribute (FixedMemory->Information);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].StartRange = FixedMemory->BaseAddress;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].EndRange = FixedMemory->BaseAddress + FixedMemory->Length - 1;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaResource[Count].Type = EfiIsaAcpiResourceEndOfList;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Initializes an ISA I/O Instance
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] IsaIoDevice The isa device to be initialized.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] DevicePath The device path of the isa device.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Resources The ACPI resource list.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Use the ISA IO Protocol structure template to initialize the ISA IO instance
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Count the resources including the ACPI End Tag
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync while (ResourcePtr.SmallHeader->Byte != ACPI_END_TAG_DESCRIPTOR) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Index += AcpiResourceToIsaResource (ResourcePtr, NULL);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ResourcePtr.SmallHeader = (ACPI_SMALL_RESOURCE_HEADER *) ((UINT8 *) ResourcePtr.SmallHeader
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ResourcePtr.LargeHeader = (ACPI_LARGE_RESOURCE_HEADER *) ((UINT8 *) ResourcePtr.LargeHeader
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Get the Isa Resource count for ACPI End Tag
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Index += AcpiResourceToIsaResource (ResourcePtr, NULL);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Initialize the ResourceList
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaIoDevice->IsaIo.ResourceList = AllocatePool (sizeof (EFI_ISA_ACPI_RESOURCE_LIST) + Index * sizeof (EFI_ISA_ACPI_RESOURCE));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaIoDevice->IsaIo.ResourceList->ResourceItem = (EFI_ISA_ACPI_RESOURCE *) (IsaIoDevice->IsaIo.ResourceList + 1);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync AcpiNode = (ACPI_HID_DEVICE_PATH *) ((UINT8 *) DevicePath + GetDevicePathSize (DevicePath) - END_DEVICE_PATH_LENGTH - sizeof (ACPI_HID_DEVICE_PATH));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaIoDevice->IsaIo.ResourceList->Device.HID = AcpiNode->HID;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaIoDevice->IsaIo.ResourceList->Device.UID = AcpiNode->UID;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync while (ResourcePtr.SmallHeader->Byte != ACPI_END_TAG_DESCRIPTOR) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Index += AcpiResourceToIsaResource (ResourcePtr, &IsaIoDevice->IsaIo.ResourceList->ResourceItem[Index]);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ResourcePtr.SmallHeader = (ACPI_SMALL_RESOURCE_HEADER *) ((UINT8 *) ResourcePtr.SmallHeader
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ResourcePtr.LargeHeader = (ACPI_LARGE_RESOURCE_HEADER *) ((UINT8 *) ResourcePtr.LargeHeader
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Convert the ACPI End Tag
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync AcpiResourceToIsaResource (ResourcePtr, &IsaIoDevice->IsaIo.ResourceList->ResourceItem[Index]);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Performs an ISA I/O Read Cycle
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] This A pointer to the EFI_ISA_IO_PROTOCOL instance.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Width Specifies the width of the I/O operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Offset The offset in ISA I/O space to start the I/O operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Count The number of I/O operations to perform.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[out] Buffer The destination buffer to store the results
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The data was read from the device sucessfully.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_UNSUPPORTED The Offset is not valid for this device.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Verify Isa IO Access
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Performs an ISA I/O Write Cycle
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] This A pointer to the EFI_ISA_IO_PROTOCOL instance.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Width Specifies the width of the I/O operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Offset The offset in ISA I/O space to start the I/O operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Count The number of I/O operations to perform.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Buffer The source buffer to write data from
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The data was writen to the device sucessfully.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_UNSUPPORTED The Offset is not valid for this device.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Verify Isa IO Access
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Writes an 8-bit I/O Port
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] This A pointer to the EFI_ISA_IO_PROTOCOL instance.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Offset The offset in ISA IO space to start the IO operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Value The data to write port.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS Success.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER Parameter is invalid.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_UNSUPPORTED The address range specified by Offset is not valid.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Wait for 50 microseconds to take affect.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Writes I/O operation base address and count number to a 8 bit I/O Port.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] This A pointer to the EFI_ISA_IO_PROTOCOL instance.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] AddrOffset The address' offset.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] PageOffset The page's offest.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] CountOffset The count's offset.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] BaseAddress The base address.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Count The number of I/O operations to perform.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS Success.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER Parameter is invalid.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_UNSUPPORTED The address range specified by these Offsets and Count is not valid.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = WritePort (This, AddrOffset, (UINT8) (BaseAddress & 0xff));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = WritePort (This, AddrOffset, (UINT8) ((BaseAddress >> 8) & 0xff));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = WritePort (This, PageOffset, (UINT8) ((BaseAddress >> 16) & 0xff));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = WritePort (This, CountOffset, (UINT8) (Count & 0xff));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = WritePort (This, CountOffset, (UINT8) ((Count >> 8) & 0xff));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Unmaps a memory region for DMA
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] This A pointer to the EFI_ISA_IO_PROTOCOL instance.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Mapping The mapping value returned from EFI_ISA_IO.Map().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The range was unmapped.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Check if DMA is supported.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((PcdGet8 (PcdIsaBusSupportedFeatures) & PCD_ISA_BUS_SUPPORT_DMA) == 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // See if the Map() operation associated with this Unmap() required a mapping
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // buffer.If a mapping buffer was not required, then this function simply
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // returns EFI_SUCCESS.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Get the MAP_INFO structure from Mapping
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If this is a write operation from the Agent's point of view,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // then copy the contents of the mapped buffer into the real buffer
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // so the processor can read the contents of the real buffer.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (IsaMapInfo->Operation == EfiIsaIoOperationBusMasterWrite) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Free the mapped buffer and the MAP_INFO structure.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync gBS->FreePages (IsaMapInfo->MappedHostAddress, IsaMapInfo->NumberOfPages);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Flushes any posted write data to the system memory.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] This A pointer to the EFI_ISA_IO_PROTOCOL instance.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The buffers were flushed.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_DEVICE_ERROR The buffers were not flushed due to a hardware error.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = IsaIoDevice->PciIo->Flush (IsaIoDevice->PciIo);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Performs an ISA Memory Read Cycle
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] This A pointer to the EFI_ISA_IO_PROTOCOL instance.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Width Specifies the width of the memory operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Offset The offset in ISA memory space to start the memory operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Count The number of memory operations to perform.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[out] Buffer The destination buffer to store the results
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The data was read from the device successfully.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_UNSUPPORTED The Offset is not valid for this device.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Check if ISA memory is supported.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((PcdGet8 (PcdIsaBusSupportedFeatures) & PCD_ISA_BUS_SUPPORT_ISA_MEMORY) == 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Verify the Isa Io Access
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Performs an ISA Memory Write Cycle
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] This A pointer to the EFI_ISA_IO_PROTOCOL instance.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Width Specifies the width of the memory operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Offset The offset in ISA memory space to start the memory operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Count The number of memory operations to perform.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Buffer The source buffer to write data from
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The data was written to the device sucessfully.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_UNSUPPORTED The Offset is not valid for this device.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Check if ISA memory is supported.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((PcdGet8 (PcdIsaBusSupportedFeatures) & PCD_ISA_BUS_SUPPORT_ISA_MEMORY) == 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Verify Isa IO Access
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Copy one region of ISA memory space to another region of ISA memory space on the ISA controller.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] This A pointer to the EFI_ISA_IO_PROTOCOL instance.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Width Specifies the width of the memory copy operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] DestOffset The offset of the destination
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] SrcOffset The offset of the source
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Count The number of memory copy operations to perform
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The data was copied sucessfully.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_UNSUPPORTED The DestOffset or SrcOffset is not valid for this device.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Check if ISA memory is supported.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((PcdGet8 (PcdIsaBusSupportedFeatures) & PCD_ISA_BUS_SUPPORT_ISA_MEMORY) == 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Verify Isa IO Access for destination and source
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Maps a memory region for DMA, note this implementation
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync only supports slave read/write operation to save code size.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param This A pointer to the EFI_ISA_IO_PROTOCOL instance.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param Operation Indicates the type of DMA (slave or bus master), and if
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync the DMA operation is going to read or write to system memory.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param ChannelNumber The slave channel number to use for this DMA operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync If Operation and ChannelAttributes shows that this device
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync performs bus mastering DMA, then this field is ignored.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync The legal range for this field is 0..7.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param ChannelAttributes The attributes of the DMA channel to use for this DMA operation
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param HostAddress The system memory address to map to the device.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param NumberOfBytes On input the number of bytes to map. On output the number
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync of bytes that were mapped.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param DeviceAddress The resulting map address for the bus master device to use
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync to access the hosts HostAddress.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param Mapping A resulting value to pass to EFI_ISA_IO.Unmap().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER The Operation or HostAddress is undefined.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_UNSUPPORTED The HostAddress can not be mapped as a common buffer.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Initialize the return values to their defaults
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Make sure the Operation parameter is valid.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Light IsaIo only supports two operations.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // The Light IsaIo doesn't support channelNumber larger than 4.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Map the HostAddress to a DeviceAddress.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((PhysicalAddress + *NumberOfBytes) > BASE_16MB) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Common Buffer operations can not be remapped. If the common buffer
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // is above 16MB, then it is not possible to generate a mapping, so return
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // an error.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (Operation == EfiIsaIoOperationBusMasterCommonBuffer) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Allocate an ISA_MAP_INFO structure to remember the mapping when Unmap()
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // is called later.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Return a pointer to the MAP_INFO structure in Mapping
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Initialize the MAP_INFO structure
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaMapInfo->NumberOfPages = EFI_SIZE_TO_PAGES (*NumberOfBytes);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Allocate a buffer below 16MB to map the transfer to.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If this is a read operation from the DMA agents's point of view,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // then copy the contents of the real buffer into the mapped buffer
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // so the DMA agent can read the contents of the real buffer.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // The DeviceAddress is the address of the maped buffer below 16 MB
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // The transfer is below 16 MB, so the DeviceAddress is simply the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // HostAddress
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Figure out what to program into the DMA Channel Mode Register
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync DmaMode = (UINT8) (B_8237_DMA_CHMODE_INCREMENT | (ChannelNumber & 0x03));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // We only support EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SINGLE_MODE in simplified IsaIo
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // A Slave DMA transfer can not cross a 64K boundary.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Compute *NumberOfBytes based on this restriction.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync MaxNumberOfBytes = 0x10000 - ((UINT32) (*DeviceAddress) & 0xffff);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Compute the values to program into the BaseAddress and Count registers
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // of the Slave DMA controller
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Program the DMA Write Single Mask Register for ChannelNumber
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Clear the DMA Byte Pointer Register
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync (UINT8) (B_8237_DMA_WRSMSK_CMS | (ChannelNumber & 0x03))
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync (UINT8) (B_8237_DMA_WRSMSK_CMS | (ChannelNumber & 0x03))
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = WritePort (This, DmaChannelMode, DmaMode);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Maps a memory region for DMA. This implementation implement the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync the full mapping support.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param This A pointer to the EFI_ISA_IO_PROTOCOL instance.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param Operation Indicates the type of DMA (slave or bus master), and if
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync the DMA operation is going to read or write to system memory.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param ChannelNumber The slave channel number to use for this DMA operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync If Operation and ChannelAttributes shows that this device
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync performs bus mastering DMA, then this field is ignored.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync The legal range for this field is 0..7.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param ChannelAttributes The attributes of the DMA channel to use for this DMA operation
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param HostAddress The system memory address to map to the device.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param NumberOfBytes On input the number of bytes to map. On output the number
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync of bytes that were mapped.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param DeviceAddress The resulting map address for the bus master device to use
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync to access the hosts HostAddress.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param Mapping A resulting value to pass to EFI_ISA_IO.Unmap().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS - The range was mapped for the returned NumberOfBytes.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER - The Operation or HostAddress is undefined.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_UNSUPPORTED - The HostAddress can not be mapped as a common buffer.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_DEVICE_ERROR - The system hardware could not map the requested address.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_OUT_OF_RESOURCES - The memory pages could not be allocated.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Initialize the return values to their defaults
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Make sure the Operation parameter is valid
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (Operation < 0 || Operation >= EfiIsaIoOperationMaximum) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // See if this is a Slave DMA Operation
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Make sure that ChannelNumber is a valid channel number
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Channel 4 is used to cascade, so it is illegal.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // This implementation only support COMPATIBLE DMA Transfers
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_COMPATIBLE) == 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If this is Channel 0..3, then the width must be 8 bit
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (((ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_8) == 0) ||
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ((ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_16) != 0)
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If this is Channel 4..7, then the width must be 16 bit
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (((ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_8) != 0) ||
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ((ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_16) == 0)) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Either Demand Mode or Single Mode must be selected, but not both
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SINGLE_MODE) != 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_DEMAND_MODE) != 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_DEMAND_MODE) == 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Map the HostAddress to a DeviceAddress.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((PhysicalAddress +*NumberOfBytes) > BASE_16MB) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Common Buffer operations can not be remapped. If the common buffer
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // is above 16MB, then it is not possible to generate a mapping, so return
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // an error.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (Operation == EfiIsaIoOperationBusMasterCommonBuffer) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Allocate an ISA_MAP_INFO structure to remember the mapping when Unmap()
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // is called later.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Return a pointer to the MAP_INFO structure in Mapping
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Initialize the MAP_INFO structure
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IsaMapInfo->NumberOfPages = EFI_SIZE_TO_PAGES (*NumberOfBytes);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Allocate a buffer below 16MB to map the transfer to.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If this is a read operation from the DMA agents's point of view,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // then copy the contents of the real buffer into the mapped buffer
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // so the DMA agent can read the contents of the real buffer.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // The DeviceAddress is the address of the maped buffer below 16 MB
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // The transfer is below 16 MB, so the DeviceAddress is simply the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // HostAddress
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If this is a Bus Master operation then return
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Figure out what to program into the DMA Channel Mode Register
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync DmaMode = (UINT8) (B_8237_DMA_CHMODE_INCREMENT | (ChannelNumber & 0x03));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_AUTO_INITIALIZE) != 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_DEMAND_MODE) != 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SINGLE_MODE) != 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // A Slave DMA transfer can not cross a 64K boundary.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Compute *NumberOfBytes based on this restriction.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync MaxNumberOfBytes = 0x10000 - ((UINT32) (*DeviceAddress) & 0xffff);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Compute the values to program into the BaseAddress and Count registers
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // of the Slave DMA controller
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync BaseAddress = (UINT32) (((UINT32) (*DeviceAddress) & 0xff0000) | (((UINT32) (*DeviceAddress) & 0xffff) >> 1));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Program the DMA Write Single Mask Register for ChannelNumber
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Clear the DMA Byte Pointer Register
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync (UINT8) (B_8237_DMA_WRSMSK_CMS | (ChannelNumber & 0x03))
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync (UINT8) (B_8237_DMA_WRSMSK_CMS | (ChannelNumber & 0x03))
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = WritePort (This, DmaChannelMode, DmaMode);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Maps a memory region for DMA
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param This A pointer to the EFI_ISA_IO_PROTOCOL instance.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param Operation Indicates the type of DMA (slave or bus master), and if
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync the DMA operation is going to read or write to system memory.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param ChannelNumber The slave channel number to use for this DMA operation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync If Operation and ChannelAttributes shows that this device
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync performs bus mastering DMA, then this field is ignored.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync The legal range for this field is 0..7.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param ChannelAttributes The attributes of the DMA channel to use for this DMA operation
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param HostAddress The system memory address to map to the device.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param NumberOfBytes On input the number of bytes to map. On output the number
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync of bytes that were mapped.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param DeviceAddress The resulting map address for the bus master device to use
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync to access the hosts HostAddress.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param Mapping A resulting value to pass to EFI_ISA_IO.Unmap().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER The Operation or HostAddress is undefined.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_UNSUPPORTED The HostAddress can not be mapped as a common buffer.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Check if DMA is supported.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((PcdGet8 (PcdIsaBusSupportedFeatures) & PCD_ISA_BUS_SUPPORT_DMA) == 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Set Feature Flag PcdIsaBusSupportBusMaster to FALSE to disable support for
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // ISA Bus Master.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // So we just return EFI_UNSUPPORTED for these functions.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((PcdGet8 (PcdIsaBusSupportedFeatures) & PCD_ISA_BUS_ONLY_SUPPORT_SLAVE_DMA) != 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Allocates pages that are suitable for an EfiIsaIoOperationBusMasterCommonBuffer mapping.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] This A pointer to the EFI_ISA_IO_PROTOCOL instance.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Type The type allocation to perform.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] MemoryType The type of memory to allocate.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Pages The number of pages to allocate.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[out] HostAddress A pointer to store the base address of the allocated range.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Attributes The requested bit mask of attributes for the allocated range.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The requested memory pages were allocated.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER Type is invalid or MemoryType is invalid or HostAddress is NULL
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_UNSUPPORTED Attributes is unsupported or the memory range specified
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync by HostAddress, Pages, and Type is not available for common buffer use.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Set Feature Flag PcdIsaBusOnlySupportSlaveDma to FALSE to disable support for
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // ISA Bus Master.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Or unset Feature Flag PcdIsaBusSupportDma to disable support for ISA DMA.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (((PcdGet8 (PcdIsaBusSupportedFeatures) & PCD_ISA_BUS_SUPPORT_DMA) == 0) ||
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ((PcdGet8 (PcdIsaBusSupportedFeatures) & PCD_ISA_BUS_ONLY_SUPPORT_SLAVE_DMA) != 0)) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (Type < AllocateAnyPages || Type >= MaxAllocateType) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (MemoryType != EfiBootServicesData && MemoryType != EfiRuntimeServicesData) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((Attributes & ~(EFI_ISA_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE | EFI_ISA_IO_ATTRIBUTE_MEMORY_CACHED)) != 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) (BASE_16MB - 1);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = gBS->AllocatePages (Type, MemoryType, Pages, &PhysicalAddress);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Frees memory that was allocated with EFI_ISA_IO.AllocateBuffer().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] This A pointer to the EFI_ISA_IO_PROTOCOL instance.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Pages The number of pages to free.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] HostAddress The base address of the allocated range.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The requested memory pages were freed.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER The memory was not allocated with EFI_ISA_IO.AllocateBufer().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Set Feature Flag PcdIsaBusOnlySupportSlaveDma to FALSE to disable support for
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // ISA Bus Master.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Or unset Feature Flag PcdIsaBusSupportDma to disable support for ISA DMA.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (((PcdGet8 (PcdIsaBusSupportedFeatures) & PCD_ISA_BUS_SUPPORT_DMA) == 0) ||