Ignore:
Timestamp:
2015-07-03T03:54:45Z (9 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8fc61c8
Parents:
e6d7df1
Message:

ehci, libusbhost: Move malloc32 to libusbhost.

So it can be shared with other HCDs.
Make sure the memory is mapped before returning from malloc32.
Add poison.

Fixes non-cntl transfers for ehci

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/utils/malloc32.h

    re6d7df1 r45cbf897  
    3535#define DRV_EHCI_UTILS_MALLOC32_H
    3636
     37#include <align.h>
    3738#include <as.h>
    3839#include <ddi.h>
     
    6566}
    6667
    67 /** Create 4KB page mapping
    68  *
    69  * @return Address of the mapped page, NULL on failure.
    70  */
    71 static inline void *get_page(void)
    72 {
    73         uintptr_t phys;
    74         void *address = AS_AREA_ANY;
    75 
    76         const int ret = dmamem_map_anonymous(EHCI_REQUIRED_PAGE_SIZE,
    77             DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
    78             &address);
    79 
    80         return ((ret == EOK) ? address : NULL);
    81 }
    82 
    83 static inline void return_page(void *page)
    84 {
    85         dmamem_unmap_anonymous(page);
    86 }
    87 
    8868/** Physical mallocator simulator
    8969 *
     
    9373static inline void * malloc32(size_t size)
    9474{
    95         assert(size < PAGE_SIZE);
    96         return get_page();
     75        uintptr_t phys;
     76        void *address = AS_AREA_ANY;
     77        size_t real_size = ALIGN_UP(size, PAGE_SIZE);
     78
     79        const int ret = dmamem_map_anonymous(real_size,
     80            DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
     81            &address);
     82
     83        if (ret == EOK) {
     84                /* Poison, accessing it should be enough to make sure
     85                 * the location is mapped, but poison works better */
     86                memset(address, 0x5, real_size);
     87                return address;
     88        }
     89        return NULL;
    9790}
    9891
     
    10396static inline void free32(void *addr)
    10497{
    105         return_page(addr);
     98        dmamem_unmap_anonymous(addr);
    10699}
     100
     101/** Create 4KB page mapping
     102 *
     103 * @return Address of the mapped page, NULL on failure.
     104 */
     105static inline void *get_page()
     106{
     107        return malloc32(PAGE_SIZE);
     108}
     109
     110static inline void return_page(void *page)
     111{
     112        free32(page);
     113}
     114
    107115
    108116#endif
Note: See TracChangeset for help on using the changeset viewer.