Changeset fd9f4ffe in mainline


Ignore:
Timestamp:
2017-07-12T16:11:22Z (7 years ago)
Author:
Jaroslav Jindrak <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
481af21e
Parents:
c9c0e41
Message:

The xHC now properly gets the physical addresses (with correct endianity) of its scratchpad buffers.

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

Legend:

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

    rc9c0e41 rfd9f4ffe  
    4141#include "hc.h"
    4242#include "hw_struct/trb.h"
    43 #include "scratchpad.h"
    4443#include "commands.h"
    4544
  • uspace/drv/bus/usb/xhci/hc.h

    rc9c0e41 rfd9f4ffe  
    4040#include "hw_struct/regs.h"
    4141#include "hw_struct/context.h"
     42#include "scratchpad.h"
    4243#include "trb_ring.h"
    4344
     
    6667        xhci_event_ring_t event_ring;
    6768        xhci_device_ctx_t **dcbaa;
     69        xhci_scratchpad_t *scratchpad;
    6870
    6971        /* Cached capabilities */
  • uspace/drv/bus/usb/xhci/scratchpad.c

    rc9c0e41 rfd9f4ffe  
    5454{
    5555        unsigned num_bufs, allocated;
    56         xhci_scratchpad_t *buf_array;
     56        xhci_scratchpad_t *bufs;
    5757
    5858        num_bufs = xhci_scratchpad_count(hc);
     
    6161                return EOK;
    6262
    63         buf_array = malloc32(num_bufs * sizeof(xhci_scratchpad_t));
    64         if (!buf_array)
     63        bufs = malloc32(sizeof(xhci_scratchpad_t));
     64        if (!bufs)
    6565                return ENOMEM;
    6666
    67         hc->dcbaa[0] = (xhci_device_ctx_t *) buf_array;
     67        allocated = 0;
    6868
    69         allocated = 0;
     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;
     76
    7077        for (unsigned i = 0; i < num_bufs; ++i) {
    71                 buf_array[i].sp_ptr = (uint64_t) malloc32(PAGE_SIZE);
     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;
    7281
    73                 if (buf_array[i].sp_ptr)
     82                if (buf != NULL)
    7483                        ++allocated;
    7584                else
    7685                        goto err_page_alloc;
    7786
    78                 memset((void *) buf_array[i].sp_ptr, 0, PAGE_SIZE);
     87                memset(buf, 0, PAGE_SIZE);
    7988        }
     89
     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] = (xhci_device_ctx_t *) bufs->phys_ptr;
     95        hc->scratchpad = bufs;
    8096
    8197        usb_log_debug2("Allocated %d scratchpad buffers.", num_bufs);
     
    85101err_page_alloc:
    86102        for (unsigned i = 0; i < allocated; ++i)
    87                 free32((void *) buf_array[i].sp_ptr);
     103                free32((void *) virt_array[i]);
     104        free32(virt_array);
     105
     106err_virt_array:
     107        free32(phys_array);
     108
     109err_phys_array:
     110        free32(bufs);
    88111
    89112        return ENOMEM;
     
    93116{
    94117        unsigned num_bufs;
    95         xhci_scratchpad_t *buf_array;
    96 
     118        xhci_scratchpad_t *scratchpad;
     119        uint64_t *virt_array;
     120       
    97121        num_bufs = xhci_scratchpad_count(hc);
    98122        if(!num_bufs)
    99123                return;
    100124
    101         buf_array = (xhci_scratchpad_t *) hc->dcbaa[0];
     125        scratchpad =  hc->scratchpad;
     126        virt_array = (uint64_t *) scratchpad->virt_ptr;
    102127
    103128        for (unsigned i = 0; i < num_bufs; ++i)
    104                 free32((void *) buf_array[i].sp_ptr);
    105         free32(buf_array);
     129                free32((void *) virt_array[i]);
     130        free32((void *) scratchpad->virt_ptr);
     131        free32((void *) scratchpad->phys_bck);
    106132
    107133        hc->dcbaa[0] = NULL;
  • uspace/drv/bus/usb/xhci/scratchpad.h

    rc9c0e41 rfd9f4ffe  
    4141#define XHCI_SCRATCHPAD_H
    4242
     43typedef struct xhci_hc xhci_hc_t;
     44
    4345typedef struct xhci_scratchpad {
    44         uint64_t sp_ptr;
     46        /* Pointers to scratchpad buffers used by the xHC. */
     47        uint64_t phys_ptr;
     48        /* Pointers to scratchpad buffers used for deallocation. */
     49        uint64_t virt_ptr;
     50        /* Pointers to the scratchpad array used for deallocation. */
     51        uint64_t phys_bck;
    4552} xhci_scratchpad_t;
    4653
Note: See TracChangeset for help on using the changeset viewer.