/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to dma/ipe.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-11-20 13:57:46 UTC
  • Revision ID: csa@suren.me-20151120135746-92cprl3ofi65u6io
Support static DMA regions in IPEDMA

Show diffs side-by-side

added added

removed removed

Lines of Context:
135
135
 
136
136
    ipe_dma_t *ctx = (ipe_dma_t*)vctx;
137
137
 
 
138
    pcilib_kmem_handle_t *desc = NULL;
 
139
    pcilib_kmem_handle_t *pages = NULL;
 
140
 
138
141
#ifndef IPEDMA_TLP_SIZE
139
142
    const pcilib_pcie_link_info_t *link_info;
140
143
#endif /* ! IPEDMA_TLP_SIZE */
148
151
 
149
152
    pcilib_register_value_t value;
150
153
 
 
154
    uintptr_t dma_region = 0;
151
155
    int tlp_size;
152
156
    uint32_t address64;
153
157
 
166
170
        link_info = pcilib_get_pcie_link_info(vctx->pcilib);
167
171
        if (link_info) {
168
172
            tlp_size = 1<<link_info->payload;
 
173
# ifdef IPEDMA_MAX_TLP_SIZE
169
174
            if (tlp_size > IPEDMA_MAX_TLP_SIZE)
170
175
                tlp_size = IPEDMA_MAX_TLP_SIZE;
 
176
# endif /* IPEDMA_MAX_TLP_SIZE */
171
177
        } else tlp_size = 128;
172
178
#endif /* IPEDMA_TLP_SIZE */
173
179
 
192
198
    else
193
199
        ctx->ring_size = IPEDMA_DMA_PAGES;
194
200
 
 
201
    if (!pcilib_read_register(ctx->dmactx.pcilib, "dmaconf", "dma_region_low", &value)) {
 
202
        dma_region = value;
 
203
        if (!pcilib_read_register(ctx->dmactx.pcilib, "dmaconf", "dma_region_low", &value)) 
 
204
            dma_region |= ((uintptr_t)value)<<32;
 
205
    }
 
206
 
195
207
    if (!pcilib_read_register(ctx->dmactx.pcilib, "dmaconf", "ipedma_flags", &value))
196
208
        ctx->dma_flags = value;
197
209
    else
208
220
#endif /* IPEDMA_CONFIGURE_DMA_MASK */
209
221
 
210
222
    kflags = PCILIB_KMEM_FLAG_REUSE|PCILIB_KMEM_FLAG_EXCLUSIVE|PCILIB_KMEM_FLAG_HARDWARE|(ctx->preserve?PCILIB_KMEM_FLAG_PERSISTENT:0);
211
 
    pcilib_kmem_handle_t *desc = pcilib_alloc_kernel_memory(ctx->dmactx.pcilib, PCILIB_KMEM_TYPE_CONSISTENT, 1, IPEDMA_DESCRIPTOR_SIZE, IPEDMA_DESCRIPTOR_ALIGNMENT, PCILIB_KMEM_USE(PCILIB_KMEM_USE_DMA_RING, 0x00), kflags);
212
 
    pcilib_kmem_handle_t *pages = pcilib_alloc_kernel_memory(ctx->dmactx.pcilib, PCILIB_KMEM_TYPE_DMA_C2S_PAGE, ctx->ring_size, ctx->page_size, 0, PCILIB_KMEM_USE(PCILIB_KMEM_USE_DMA_PAGES, 0x00), kflags);
 
223
 
 
224
    desc = pcilib_alloc_kernel_memory(ctx->dmactx.pcilib, PCILIB_KMEM_TYPE_CONSISTENT, 1, IPEDMA_DESCRIPTOR_SIZE, IPEDMA_DESCRIPTOR_ALIGNMENT, PCILIB_KMEM_USE(PCILIB_KMEM_USE_DMA_RING, 0x00), kflags);
 
225
    if (dma_region)
 
226
        pages = pcilib_alloc_kernel_memory(ctx->dmactx.pcilib, PCILIB_KMEM_TYPE_REGION_C2S, ctx->ring_size, ctx->page_size, dma_region, PCILIB_KMEM_USE(PCILIB_KMEM_USE_DMA_PAGES, 0x00), kflags);
 
227
    else
 
228
        pages = pcilib_alloc_kernel_memory(ctx->dmactx.pcilib, PCILIB_KMEM_TYPE_DMA_C2S_PAGE, ctx->ring_size, ctx->page_size, 0, PCILIB_KMEM_USE(PCILIB_KMEM_USE_DMA_PAGES, 0x00), kflags);
213
229
 
214
230
    if (!desc||!pages) {
215
231
        if (pages) pcilib_free_kernel_memory(ctx->dmactx.pcilib, pages, KMEM_FLAG_REUSE);
216
232
        if (desc) pcilib_free_kernel_memory(ctx->dmactx.pcilib, desc, KMEM_FLAG_REUSE);
217
 
        printf("%lu\n", IPEDMA_DESCRIPTOR_SIZE);
218
233
        pcilib_error("Can't allocate required kernel memory for IPEDMA engine (%lu pages of %lu bytes + %lu byte descriptor)", ctx->ring_size, ctx->page_size, (unsigned long)IPEDMA_DESCRIPTOR_SIZE);
219
234
        return PCILIB_ERROR_MEMORY;
220
235
    }
227
242
        pcilib_free_kernel_memory(ctx->dmactx.pcilib, pages, KMEM_FLAG_REUSE);
228
243
        pcilib_free_kernel_memory(ctx->dmactx.pcilib, desc, KMEM_FLAG_REUSE);
229
244
 
230
 
        if ((flags&PCILIB_DMA_FLAG_STOP) == 0) {
 
245
        if (((flags&PCILIB_DMA_FLAG_STOP) == 0)||(dma_region)) {
231
246
            pcilib_error("Inconsistent DMA buffers are found (buffers are only partially re-used). This is very wrong, please stop DMA engine and correct configuration...");
232
247
            return PCILIB_ERROR_INVALID_STATE;
233
248
        }