Ignore:
Timestamp:
2016-07-22T08:24:47Z (9 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f76d2c2
Parents:
5b18137 (diff), 8351f9a4 (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 from lp:~jan.vesely/helenos/usb

File:
1 moved

Legend:

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

    r5b18137 rb4b534ac  
    11/*
    2  * Copyright (c) 2010 Jan Vesely
     2 * Copyright (c) 2013 Jan Vesely
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbohci
     28/** @addtogroup drvusbehci
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief OHCI driver
     32 * @brief EHCI driver
    3333 */
    34 #ifndef DRV_OHCI_UTILS_MALLOC32_H
    35 #define DRV_OHCI_UTILS_MALLOC32_H
     34#ifndef DRV_EHCI_UTILS_MALLOC32_H
     35#define DRV_EHCI_UTILS_MALLOC32_H
    3636
    37 #include <assert.h>
    38 #include <malloc.h>
    39 #include <unistd.h>
     37#include <align.h>
     38#include <as.h>
     39#include <ddi.h>
    4040#include <errno.h>
    41 #include <mem.h>
    42 #include <as.h>
     41#include <stdlib.h>
     42#include <sys/types.h>
    4343
    4444/* Generic TDs and EDs require 16byte alignment,
     
    4646 * buffers do not have to be aligned.
    4747 */
    48 #define OHCI_ALIGN 32
     48#define EHCI_ALIGN   32
     49
     50#define EHCI_REQUIRED_PAGE_SIZE   4096
    4951
    5052/** Get physical address translation
     
    7072 */
    7173static inline void * malloc32(size_t size)
    72         { return memalign(OHCI_ALIGN, size); }
     74{
     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;
     90}
    7391
    7492/** Physical mallocator simulator
     
    7795 */
    7896static inline void free32(void *addr)
    79         { free(addr); }
     97{
     98        dmamem_unmap_anonymous(addr);
     99}
     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
     115
    80116#endif
    81117/**
Note: See TracChangeset for help on using the changeset viewer.