Changeset b80c1ab in mainline for uspace/drv/bus/usb/xhci/scratchpad.c


Ignore:
Timestamp:
2017-11-14T23:17:54Z (6 years ago)
Author:
Aearsis <Hlavaty.Ondrej@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e76c0ea
Parents:
cfe4852
git-author:
Aearsis <Hlavaty.Ondrej@…> (2017-11-14 23:15:24)
git-committer:
Aearsis <Hlavaty.Ondrej@…> (2017-11-14 23:17:54)
Message:

xhci: use dma_buffers instead of malloc32 util

A bit of refactoring was needed to adapt scratchpad buffers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/scratchpad.c

    rcfe4852 rb80c1ab  
    3636#include <errno.h>
    3737#include <usb/debug.h>
    38 #include <usb/host/utils/malloc32.h>
    3938#include "hc.h"
    4039#include "hw_struct/regs.h"
     
    5352int xhci_scratchpad_alloc(xhci_hc_t *hc)
    5453{
    55         unsigned num_bufs, allocated;
    56         xhci_scratchpad_t *bufs;
    57 
    58         num_bufs = xhci_scratchpad_count(hc);
     54        const unsigned num_bufs = xhci_scratchpad_count(hc);
    5955
    6056        if (!num_bufs)
    6157                return EOK;
    6258
    63         bufs = malloc32(sizeof(xhci_scratchpad_t));
    64         if (!bufs)
     59        if (dma_buffer_alloc(&hc->scratchpad_array, num_bufs * sizeof(uint64_t)))
    6560                return ENOMEM;
     61        uint64_t *phys_array = hc->scratchpad_array.virt;
    6662
    67         allocated = 0;
     63        hc->dcbaa[0] = host2xhci(64, hc->scratchpad_array.phys);
    6864
    69         uint64_t *phys_array = malloc32(num_bufs * sizeof(uint64_t));
    70         if (phys_array == NULL)
    71                 goto err_phys_array;
    72 
    73         uint64_t *virt_array = malloc32(num_bufs * sizeof(uint64_t));
    74         if (virt_array == NULL)
    75                 goto err_virt_array;
     65        hc->scratchpad_buffers = calloc(num_bufs, sizeof(dma_buffer_t));
     66        if (!hc->scratchpad_buffers)
     67                goto err_dma;
    7668
    7769        for (unsigned i = 0; i < num_bufs; ++i) {
    78                 void *buf = malloc32(PAGE_SIZE);
    79                 phys_array[i] = host2xhci(64, (uint64_t) addr_to_phys(buf));
    80                 virt_array[i] = (uint64_t) buf;
     70                dma_buffer_t *cur = &hc->scratchpad_buffers[i];
     71                if (dma_buffer_alloc(cur, PAGE_SIZE))
     72                        goto err_buffers;
    8173
    82                 if (buf != NULL)
    83                         ++allocated;
    84                 else
    85                         goto err_page_alloc;
    86 
    87                 memset(buf, 0, PAGE_SIZE);
     74                memset(cur->virt, 0, PAGE_SIZE);
     75                phys_array[i] = host2xhci(64, cur->phys);
    8876        }
    8977
    90         bufs->phys_ptr = host2xhci(64, (uint64_t) addr_to_phys(phys_array));
    91         bufs->virt_ptr = (uint64_t) virt_array;
    92         bufs->phys_bck = (uint64_t) phys_array;
    93 
    94         hc->dcbaa[0] = bufs->phys_ptr;
    95         hc->scratchpad = bufs;
    9678
    9779        usb_log_debug2("Allocated %d scratchpad buffers.", num_bufs);
     
    9981        return EOK;
    10082
    101 err_page_alloc:
    102         for (unsigned i = 0; i < allocated; ++i)
    103                 free32((void *) virt_array[i]);
    104         free32(virt_array);
    105 
    106 err_virt_array:
    107         free32(phys_array);
    108 
    109 err_phys_array:
    110         free32(bufs);
    111 
     83err_buffers:
     84        for (unsigned i = 0; i < num_bufs; ++i)
     85                dma_buffer_free(&hc->scratchpad_buffers[i]);
     86        free(hc->scratchpad_buffers);
     87err_dma:
     88        hc->dcbaa[0] = 0;
     89        dma_buffer_free(&hc->scratchpad_array);
    11290        return ENOMEM;
    11391}
     
    11593void xhci_scratchpad_free(xhci_hc_t *hc)
    11694{
    117         unsigned num_bufs;
    118         xhci_scratchpad_t *scratchpad;
    119         uint64_t *virt_array;
     95        const unsigned num_bufs = xhci_scratchpad_count(hc);
    12096
    121         num_bufs = xhci_scratchpad_count(hc);
    12297        if (!num_bufs)
    12398                return;
    12499
    125         scratchpad =  hc->scratchpad;
    126         virt_array = (uint64_t *) scratchpad->virt_ptr;
    127 
     100        hc->dcbaa[0] = 0;
     101        dma_buffer_free(&hc->scratchpad_array);
    128102        for (unsigned i = 0; i < num_bufs; ++i)
    129                 free32((void *) virt_array[i]);
    130         free32((void *) scratchpad->virt_ptr);
    131         free32((void *) scratchpad->phys_bck);
    132 
    133         hc->dcbaa[0] = 0;
    134 
     103                dma_buffer_free(&hc->scratchpad_buffers[i]);
     104        free(hc->scratchpad_buffers);
    135105        return;
    136106}
Note: See TracChangeset for help on using the changeset viewer.