Changeset 98893ede in mainline
- Timestamp:
- 2018-01-31T17:00:39Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 50206e9
- Parents:
- 3b60ea0
- Location:
- uspace/lib/usb
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/include/usb/dma_buffer.h
r3b60ea0 r98893ede 55 55 } dma_buffer_t; 56 56 57 extern dma_policy_t dma_policy_default;58 59 57 extern int dma_buffer_alloc(dma_buffer_t *db, size_t size); 60 extern int dma_buffer_alloc_policy(dma_buffer_t *, size_t, dma_policy_t);58 extern int dma_buffer_alloc_policy(dma_buffer_t *, size_t, const dma_policy_t *); 61 59 extern void dma_buffer_free(dma_buffer_t *); 62 60 extern uintptr_t dma_buffer_phys(const dma_buffer_t *, void *); -
uspace/lib/usb/src/dma_buffer.c
r3b60ea0 r98893ede 39 39 #include "usb/dma_buffer.h" 40 40 41 dma_policy_t dma_policy_default = {41 const dma_policy_t dma_policy_default = { 42 42 .use64 = false, 43 43 .alignment = PAGE_SIZE, … … 45 45 46 46 /** 47 * Allocate a DMA buffer. 48 * 49 * @param[in] db dma_buffer_t structure to fill 50 * @param[in] policy dma_policy_t structure to guide 51 * @param[in] size Size of the required memory space 52 * @return Error code. 47 * The routine of allocating a DMA buffer. Inlined to force optimization for the 48 * default policy. 53 49 */ 54 int dma_buffer_alloc_policy(dma_buffer_t *db, size_t size, dma_policy_t policy) 50 static inline int dma_buffer_alloc_internal(dma_buffer_t *db, 51 size_t size, const dma_policy_t *policy) 55 52 { 56 53 assert(db); 57 54 58 if (policy .alignment > PAGE_SIZE)55 if (policy->alignment > PAGE_SIZE) 59 56 return EINVAL; 60 57 61 const size_t aligned_size = ALIGN_UP(size, policy .alignment);58 const size_t aligned_size = ALIGN_UP(size, policy->alignment); 62 59 const size_t real_size = ALIGN_UP(aligned_size, PAGE_SIZE); 63 const uintptr_t flags = policy .use64 ? 0 : DMAMEM_4GiB;60 const uintptr_t flags = policy->use64 ? 0 : DMAMEM_4GiB; 64 61 65 62 uintptr_t phys; … … 71 68 72 69 if (ret == EOK) { 73 /* Poison, accessing it should be enough to make sure74 * the location is mapped, but poison works better */75 memset(address, 0x5, real_size);76 70 db->virt = address; 77 71 db->phys = phys; 78 72 } 79 73 return ret; 74 } 75 76 /** 77 * Allocate a DMA buffer. 78 * 79 * @param[in] db dma_buffer_t structure to fill 80 * @param[in] size Size of the required memory space 81 * @param[in] policy dma_policy_t structure to guide 82 * @return Error code. 83 */ 84 int dma_buffer_alloc_policy(dma_buffer_t *db, size_t size, 85 const dma_policy_t *policy) 86 { 87 return dma_buffer_alloc_internal(db, size, policy); 80 88 } 81 89 … … 89 97 int dma_buffer_alloc(dma_buffer_t *db, size_t size) 90 98 { 91 return dma_buffer_alloc_ policy(db, size,dma_policy_default);99 return dma_buffer_alloc_internal(db, size, &dma_policy_default); 92 100 } 93 101
Note:
See TracChangeset
for help on using the changeset viewer.