Changeset 45cbf897 in mainline for uspace/lib/usbhost/include/usb/host/utils/malloc32.h
- Timestamp:
- 2015-07-03T03:54:45Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8fc61c8
- Parents:
- e6d7df1
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/utils/malloc32.h
re6d7df1 r45cbf897 35 35 #define DRV_EHCI_UTILS_MALLOC32_H 36 36 37 #include <align.h> 37 38 #include <as.h> 38 39 #include <ddi.h> … … 65 66 } 66 67 67 /** Create 4KB page mapping68 *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 88 68 /** Physical mallocator simulator 89 69 * … … 93 73 static inline void * malloc32(size_t size) 94 74 { 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; 97 90 } 98 91 … … 103 96 static inline void free32(void *addr) 104 97 { 105 return_page(addr);98 dmamem_unmap_anonymous(addr); 106 99 } 100 101 /** Create 4KB page mapping 102 * 103 * @return Address of the mapped page, NULL on failure. 104 */ 105 static inline void *get_page() 106 { 107 return malloc32(PAGE_SIZE); 108 } 109 110 static inline void return_page(void *page) 111 { 112 free32(page); 113 } 114 107 115 108 116 #endif
Note:
See TracChangeset
for help on using the changeset viewer.