Changeset 83fb72e in mainline


Ignore:
Timestamp:
2017-12-20T11:36:13Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9fd8f14
Parents:
ba2fc2c
git-author:
Ondřej Hlavatý <aearsis@…> (2017-12-20 11:35:57)
git-committer:
Ondřej Hlavatý <aearsis@…> (2017-12-20 11:36:13)
Message:

xhci: allocate all scratchpads in one buffer

Location:
uspace/drv/bus/usb/xhci
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/hc.h

    rba2fc2c r83fb72e  
    7171        dma_buffer_t dcbaa_dma;
    7272        dma_buffer_t scratchpad_array;
    73         dma_buffer_t *scratchpad_buffers;
    7473
    7574        /* Command ring management */
  • uspace/drv/bus/usb/xhci/scratchpad.c

    rba2fc2c r83fb72e  
    3737#include <usb/debug.h>
    3838#include "hc.h"
     39#include <align.h>
    3940#include "hw_struct/regs.h"
    4041#include "scratchpad.h"
     
    5758                return EOK;
    5859
    59         if (dma_buffer_alloc(&hc->scratchpad_array, num_bufs * sizeof(uint64_t)))
     60        const unsigned array_size = ALIGN_UP(num_bufs * sizeof(uint64_t), PAGE_SIZE);
     61        const size_t size = array_size + num_bufs * PAGE_SIZE;
     62
     63        if (dma_buffer_alloc(&hc->scratchpad_array, size))
    6064                return ENOMEM;
    61         uint64_t *phys_array = hc->scratchpad_array.virt;
     65
     66        memset(hc->scratchpad_array.virt, 0, size);
     67
     68        uint64_t phys_begin = hc->scratchpad_array.phys + array_size;
     69        uint64_t *array = hc->scratchpad_array.virt;
     70
     71        for (unsigned i = 0; i < num_bufs; ++i)
     72                array[i] = host2xhci(64, phys_begin + i * PAGE_SIZE);
    6273
    6374        hc->dcbaa[0] = host2xhci(64, hc->scratchpad_array.phys);
    64 
    65         hc->scratchpad_buffers = calloc(num_bufs, sizeof(dma_buffer_t));
    66         if (!hc->scratchpad_buffers)
    67                 goto err_dma;
    68 
    69         for (unsigned i = 0; i < num_bufs; ++i) {
    70                 dma_buffer_t *cur = &hc->scratchpad_buffers[i];
    71                 if (dma_buffer_alloc(cur, PAGE_SIZE))
    72                         goto err_buffers;
    73 
    74                 memset(cur->virt, 0, PAGE_SIZE);
    75                 phys_array[i] = host2xhci(64, cur->phys);
    76         }
    77 
    7875
    7976        usb_log_debug2("Allocated %d scratchpad buffers.", num_bufs);
    8077
    8178        return EOK;
    82 
    83 err_buffers:
    84         for (unsigned i = 0; i < num_bufs; ++i)
    85                 dma_buffer_free(&hc->scratchpad_buffers[i]);
    86         free(hc->scratchpad_buffers);
    87 err_dma:
    88         hc->dcbaa[0] = 0;
    89         dma_buffer_free(&hc->scratchpad_array);
    90         return ENOMEM;
    9179}
    9280
     
    10088        hc->dcbaa[0] = 0;
    10189        dma_buffer_free(&hc->scratchpad_array);
    102         for (unsigned i = 0; i < num_bufs; ++i)
    103                 dma_buffer_free(&hc->scratchpad_buffers[i]);
    104         free(hc->scratchpad_buffers);
    10590        return;
    10691}
Note: See TracChangeset for help on using the changeset viewer.