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


Ignore:
Timestamp:
2017-11-14T23:17:54Z (8 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/trb_ring.c

    rcfe4852 rb80c1ab  
    3333#include <align.h>
    3434#include <usb/debug.h>
    35 #include <usb/host/utils/malloc32.h>
    3635#include "hw_struct/trb.h"
    3736#include "trb_ring.h"
     
    6867 * to DMAMEM_4GiB.
    6968 */
    70 static int trb_segment_allocate(trb_segment_t **segment)
    71 {
    72         uintptr_t phys;
    73         int err;
    74 
    75         *segment = AS_AREA_ANY;
    76         err = dmamem_map_anonymous(PAGE_SIZE,
    77             DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
    78             (void *) segment);
    79 
    80         if (err == EOK) {
    81                 memset(*segment, 0, PAGE_SIZE);
    82                 (*segment)->phys = phys;
    83 
    84                 usb_log_debug2("Allocated new ring segment.");
    85         }
    86 
    87         return err;
     69static int trb_segment_alloc(trb_segment_t **segment)
     70{
     71        dma_buffer_t dbuf;
     72
     73        const int err = dma_buffer_alloc(&dbuf, PAGE_SIZE);
     74        if (err)
     75                return err;
     76
     77        *segment = dbuf.virt;
     78        memset(*segment, 0, PAGE_SIZE);
     79        (*segment)->phys = dbuf.phys;
     80        usb_log_debug2("Allocated new ring segment.");
     81        return EOK;
     82}
     83
     84static void trb_segment_free(trb_segment_t *segment)
     85{
     86        dma_buffer_t dbuf = { .virt = segment, .phys = segment->phys };
     87        dma_buffer_free(&dbuf);
    8888}
    8989
     
    9999        list_initialize(&ring->segments);
    100100
    101         if ((err = trb_segment_allocate(&segment)) != EOK)
     101        if ((err = trb_segment_alloc(&segment)) != EOK)
    102102                return err;
    103103
     
    127127        list_foreach_safe(ring->segments, cur, next) {
    128128                trb_segment_t *segment = list_get_instance(cur, trb_segment_t, segments_link);
    129                 dmamem_unmap_anonymous(segment);
     129                trb_segment_free(segment);
    130130        }
    131131}
     
    264264        list_initialize(&ring->segments);
    265265
    266         if ((err = trb_segment_allocate(&segment)) != EOK)
     266        if ((err = trb_segment_alloc(&segment)) != EOK)
    267267                return err;
    268268
     
    274274        ring->dequeue_ptr = segment->phys;
    275275
    276         ring->erst = malloc32(PAGE_SIZE);
    277         if (ring->erst == NULL)
     276        if (dma_buffer_alloc(&ring->erst, PAGE_SIZE))
    278277                return ENOMEM;
    279         memset(ring->erst, 0, PAGE_SIZE);
    280 
    281         xhci_fill_erst_entry(&ring->erst[0], segment->phys, SEGMENT_TRB_COUNT);
     278        xhci_erst_entry_t *erst = ring->erst.virt;
     279
     280        memset(erst, 0, PAGE_SIZE);
     281        xhci_fill_erst_entry(&erst[0], segment->phys, SEGMENT_TRB_COUNT);
    282282
    283283        ring->ccs = 1;
     
    297297        }
    298298
    299         if (ring->erst)
    300                 free32(ring->erst);
     299        dma_buffer_free(&ring->erst);
    301300}
    302301
Note: See TracChangeset for help on using the changeset viewer.