andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 1 | /** @file
|
andrewfish | 81bc205 | 2010-05-29 00:21:30 +0000 | [diff] [blame] | 2 | Abstractions for simple OMAP DMA channel.
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 3 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 4 |
|
| 5 | Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 6 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 7 | This program and the accompanying materials
|
| 8 | are licensed and made available under the terms and conditions of the BSD License
|
| 9 | which accompanies this distribution. The full text of the license may be found at
|
| 10 | http://opensource.org/licenses/bsd-license.php
|
| 11 |
|
| 12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
| 13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
| 14 |
|
| 15 | **/
|
| 16 |
|
| 17 | #include <Base.h>
|
| 18 | #include <Library/DebugLib.h>
|
| 19 | #include <Library/OmapDmaLib.h>
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 20 | #include <Library/IoLib.h>
|
andrewfish | 8e7c9e0 | 2010-05-28 00:31:53 +0000 | [diff] [blame] | 21 | #include <Library/BaseMemoryLib.h>
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 22 | #include <Omap3530/Omap3530.h>
|
| 23 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 24 |
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 25 | /**
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 26 | Configure OMAP DMA Channel
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 27 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 28 | @param Channel DMA Channel to configure
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 29 | @param Dma4 Pointer to structure used to initialize DMA registers for the Channel
|
| 30 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 31 | @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
|
| 32 | @retval EFI_INVALID_PARAMETER Channel is not valid
|
| 33 | @retval EFI_DEVICE_ERROR The system hardware could not map the requested information.
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 34 |
|
andrewfish | 8e7c9e0 | 2010-05-28 00:31:53 +0000 | [diff] [blame] | 35 | **/
|
| 36 | EFI_STATUS
|
| 37 | EFIAPI
|
| 38 | EnableDmaChannel (
|
| 39 | IN UINTN Channel,
|
| 40 | IN OMAP_DMA4 *DMA4
|
| 41 | )
|
| 42 | {
|
| 43 | UINT32 RegVal;
|
| 44 |
|
| 45 |
|
| 46 | if (Channel > DMA4_MAX_CHANNEL) {
|
| 47 | return EFI_INVALID_PARAMETER;
|
| 48 | }
|
| 49 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 50 | /* 1) Configure the transfer parameters in the logical DMA registers */
|
| 51 | /*-------------------------------------------------------------------*/
|
| 52 |
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 53 | /* a) Set the data type CSDP[1:0], the Read/Write Port access type
|
| 54 | CSDP[8:7]/[15:14], the Source/dest endianism CSDP[21]/CSDP[19],
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 55 | write mode CSDP[17:16], source/dest packed or nonpacked CSDP[6]/CSDP[13] */
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 56 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 57 | // Read CSDP
|
| 58 | RegVal = MmioRead32 (DMA4_CSDP (Channel));
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 59 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 60 | // Build reg
|
| 61 | RegVal = ((RegVal & ~ 0x3) | DMA4->DataType );
|
| 62 | RegVal = ((RegVal & ~(0x3 << 7)) | (DMA4->ReadPortAccessType << 7));
|
| 63 | RegVal = ((RegVal & ~(0x3 << 14)) | (DMA4->WritePortAccessType << 14));
|
| 64 | RegVal = ((RegVal & ~(0x1 << 21)) | (DMA4->SourceEndiansim << 21));
|
| 65 | RegVal = ((RegVal & ~(0x1 << 19)) | (DMA4->DestinationEndianism << 19));
|
| 66 | RegVal = ((RegVal & ~(0x3 << 16)) | (DMA4->WriteMode << 16));
|
| 67 | RegVal = ((RegVal & ~(0x1 << 6)) | (DMA4->SourcePacked << 6));
|
| 68 | RegVal = ((RegVal & ~(0x1 << 13)) | (DMA4->DestinationPacked << 13));
|
| 69 | // Write CSDP
|
| 70 | MmioWrite32 (DMA4_CSDP (Channel), RegVal);
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 71 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 72 | /* b) Set the number of element per frame CEN[23:0]*/
|
| 73 | MmioWrite32 (DMA4_CEN (Channel), DMA4->NumberOfElementPerFrame);
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 74 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 75 | /* c) Set the number of frame per block CFN[15:0]*/
|
| 76 | MmioWrite32 (DMA4_CFN (Channel), DMA4->NumberOfFramePerTransferBlock);
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 77 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 78 | /* d) Set the Source/dest start address index CSSA[31:0]/CDSA[31:0]*/
|
| 79 | MmioWrite32 (DMA4_CSSA (Channel), DMA4->SourceStartAddress);
|
| 80 | MmioWrite32 (DMA4_CDSA (Channel), DMA4->DestinationStartAddress);
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 81 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 82 | /* e) Set the Read Port addressing mode CCR[13:12], the Write Port addressing mode CCR[15:14],
|
| 83 | read/write priority CCR[6]/CCR[26]
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 84 | I changed LCH CCR[20:19]=00 and CCR[4:0]=00000 to
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 85 | LCH CCR[20:19]= DMA4->WriteRequestNumber and CCR[4:0]=DMA4->ReadRequestNumber
|
| 86 | */
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 87 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 88 | // Read CCR
|
| 89 | RegVal = MmioRead32 (DMA4_CCR (Channel));
|
| 90 |
|
| 91 | // Build reg
|
| 92 | RegVal = ((RegVal & ~0x1f) | DMA4->ReadRequestNumber);
|
| 93 | RegVal = ((RegVal & ~(BIT20 | BIT19)) | DMA4->WriteRequestNumber << 19);
|
| 94 | RegVal = ((RegVal & ~(0x3 << 12)) | (DMA4->ReadPortAccessMode << 12));
|
| 95 | RegVal = ((RegVal & ~(0x3 << 14)) | (DMA4->WritePortAccessMode << 14));
|
| 96 | RegVal = ((RegVal & ~(0x1 << 6)) | (DMA4->ReadPriority << 6));
|
| 97 | RegVal = ((RegVal & ~(0x1 << 26)) | (DMA4->WritePriority << 26));
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 98 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 99 | // Write CCR
|
| 100 | MmioWrite32 (DMA4_CCR (Channel), RegVal);
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 101 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 102 | /* f)- Set the source element index CSEI[15:0]*/
|
| 103 | MmioWrite32 (DMA4_CSEI (Channel), DMA4->SourceElementIndex);
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 104 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 105 | /* - Set the source frame index CSFI[15:0]*/
|
| 106 | MmioWrite32 (DMA4_CSFI (Channel), DMA4->SourceFrameIndex);
|
| 107 |
|
| 108 |
|
| 109 | /* - Set the destination element index CDEI[15:0]*/
|
| 110 | MmioWrite32 (DMA4_CDEI (Channel), DMA4->DestinationElementIndex);
|
| 111 |
|
| 112 | /* - Set the destination frame index CDFI[31:0]*/
|
| 113 | MmioWrite32 (DMA4_CDFI (Channel), DMA4->DestinationFrameIndex);
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 114 |
|
andrewfish | 9f6b977 | 2010-05-11 00:06:47 +0000 | [diff] [blame] | 115 | MmioWrite32 (DMA4_CDFI (Channel), DMA4->DestinationFrameIndex);
|
| 116 |
|
| 117 | // Enable all the status bits since we are polling
|
| 118 | MmioWrite32 (DMA4_CICR (Channel), DMA4_CICR_ENABLE_ALL);
|
| 119 | MmioWrite32 (DMA4_CSR (Channel), DMA4_CSR_RESET);
|
| 120 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 121 | /* 2) Start the DMA transfer by Setting the enable bit CCR[7]=1 */
|
| 122 | /*--------------------------------------------------------------*/
|
| 123 | //write enable bit
|
andrewfish | 8e7c9e0 | 2010-05-28 00:31:53 +0000 | [diff] [blame] | 124 | MmioOr32 (DMA4_CCR(Channel), DMA4_CCR_ENABLE); //Launch transfer
|
| 125 |
|
| 126 | return EFI_SUCCESS;
|
| 127 | }
|
| 128 |
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 129 | /**
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 130 | Turn of DMA channel configured by EnableDma().
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 131 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 132 | @param Channel DMA Channel to configure
|
andrewfish | 9f6b977 | 2010-05-11 00:06:47 +0000 | [diff] [blame] | 133 | @param SuccesMask Bits in DMA4_CSR register indicate EFI_SUCCESS
|
| 134 | @param ErrorMask Bits in DMA4_CSR register indicate EFI_DEVICE_ERROR
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 135 |
|
andrewfish | 7f814ff | 2010-05-08 19:32:03 +0000 | [diff] [blame] | 136 | @retval EFI_SUCCESS DMA hardware disabled
|
| 137 | @retval EFI_INVALID_PARAMETER Channel is not valid
|
| 138 | @retval EFI_DEVICE_ERROR The system hardware could not map the requested information.
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 139 |
|
andrewfish | 8e7c9e0 | 2010-05-28 00:31:53 +0000 | [diff] [blame] | 140 | **/
|
| 141 | EFI_STATUS
|
| 142 | EFIAPI
|
| 143 | DisableDmaChannel (
|
| 144 | IN UINTN Channel,
|
| 145 | IN UINT32 SuccessMask,
|
| 146 | IN UINT32 ErrorMask
|
| 147 | )
|
| 148 | {
|
| 149 | EFI_STATUS Status = EFI_SUCCESS;
|
| 150 | UINT32 Reg;
|
| 151 |
|
| 152 |
|
| 153 | if (Channel > DMA4_MAX_CHANNEL) {
|
| 154 | return EFI_INVALID_PARAMETER;
|
| 155 | }
|
| 156 |
|
| 157 | do {
|
| 158 | Reg = MmioRead32 (DMA4_CSR(Channel));
|
| 159 | if ((Reg & ErrorMask) != 0) {
|
| 160 | Status = EFI_DEVICE_ERROR;
|
| 161 | DEBUG ((EFI_D_ERROR, "DMA Error (%d) %x\n", Channel, Reg));
|
| 162 | break;
|
| 163 | }
|
| 164 | } while ((Reg & SuccessMask) != SuccessMask);
|
| 165 |
|
| 166 |
|
| 167 | // Disable all status bits and clear them
|
andrewfish | 9f6b977 | 2010-05-11 00:06:47 +0000 | [diff] [blame] | 168 | MmioWrite32 (DMA4_CICR (Channel), 0);
|
andrewfish | 8e7c9e0 | 2010-05-28 00:31:53 +0000 | [diff] [blame] | 169 | MmioWrite32 (DMA4_CSR (Channel), DMA4_CSR_RESET);
|
| 170 |
|
Ronald Cron | 3402aac | 2014-08-19 13:29:52 +0000 | [diff] [blame] | 171 | MmioAnd32 (DMA4_CCR(0), ~(DMA4_CCR_ENABLE | DMA4_CCR_RD_ACTIVE | DMA4_CCR_WR_ACTIVE));
|
andrewfish | 8e7c9e0 | 2010-05-28 00:31:53 +0000 | [diff] [blame] | 172 | return Status;
|
| 173 | }
|
| 174 |
|
| 175 |
|
| 176 |
|