Changeset b8cab5c in mainline for uspace/drv/uhci-hcd/utils/malloc32.h


Ignore:
Timestamp:
2011-05-27T07:10:12Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ffca03c
Parents:
8bb61e6 (diff), 1889786 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge with usb/development

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/utils/malloc32.h

    r8bb61e6 rb8cab5c  
    4141#include <as.h>
    4242
    43 #include "slab.h"
    44 
    4543#define UHCI_STRCUTURES_ALIGNMENT 16
    4644#define UHCI_REQUIRED_PAGE_SIZE 4096
     
    5957        uintptr_t result;
    6058        const int ret = as_get_physical_mapping(addr, &result);
    61         assert(ret == EOK);
    62 
    6359        if (ret != EOK)
    6460                return 0;
     
    7268 */
    7369static inline void * malloc32(size_t size) {
    74         if (size <= SLAB_ELEMENT_SIZE)
    75                 return slab_malloc_g();
    76         usb_log_warning("Requested %zu bytes, current allocator can't handle "
    77             "that amount, pray that the standard malloc will suffice.", size);
    78         return memalign(UHCI_STRCUTURES_ALIGNMENT, size);
     70        /* This works only when the host has less than 4GB of memory as
     71         * physical address needs to fit into 32 bits */
     72
     73        /* If we need more than one page there is no guarantee that the
     74         * memory will be continuous */
     75        if (size > PAGE_SIZE)
     76                return NULL;
     77        /* Calculate alignment to make sure the block won't cross page
     78         * boundary */
     79        size_t alignment = UHCI_STRCUTURES_ALIGNMENT;
     80        while (alignment < size)
     81                alignment *= 2;
     82        return memalign(alignment, size);
    7983}
    8084/*----------------------------------------------------------------------------*/
     
    8690        if (!addr)
    8791                return;
    88         if (slab_in_range_g(addr))
    89                 return slab_free_g(addr);
    9092        free(addr);
    9193}
     
    98100{
    99101        void *free_address = as_get_mappable_page(UHCI_REQUIRED_PAGE_SIZE);
    100         assert(free_address); /* TODO: remove this assert */
    101102        if (free_address == 0)
    102103                return NULL;
Note: See TracChangeset for help on using the changeset viewer.