Changeset fbcdeb8 in mainline for uspace/lib/c/generic/ddi.c
- Timestamp:
- 2011-12-19T17:30:39Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 58f6229
- Parents:
- 24cf31f1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/ddi.c
r24cf31f1 rfbcdeb8 45 45 #include <align.h> 46 46 #include <libarch/config.h> 47 #include "private/libc.h" 47 48 48 49 /** Return unique device number. … … 61 62 * 62 63 * @param phys Physical address of the starting frame. 63 * @param virt Virtual address of the starting page.64 64 * @param pages Number of pages to map. 65 65 * @param flags Flags for the new address space area. 66 * @param virt Virtual address of the starting page. 66 67 * 67 68 * @return EOK on success … … 72 73 * 73 74 */ 74 int physmem_map(void *phys, void *virt, size_t pages, unsigned int flags)75 int physmem_map(void *phys, size_t pages, unsigned int flags, void **virt) 75 76 { 76 return __SYSCALL 4(SYS_PHYSMEM_MAP, (sysarg_t) phys,77 (sysarg_t) virt, pages, flags);77 return __SYSCALL5(SYS_PHYSMEM_MAP, (sysarg_t) phys, 78 pages, flags, (sysarg_t) virt, (sysarg_t) __entry); 78 79 } 79 80 … … 81 82 unsigned int flags, void **phys) 82 83 { 83 return (int) __SYSCALL 5(SYS_DMAMEM_MAP, (sysarg_t) virt,84 (sysarg_t) size, (sysarg_t) map_flags, (sysarg_t) flags,85 (sysarg_t) phys );84 return (int) __SYSCALL6(SYS_DMAMEM_MAP, (sysarg_t) size, 85 (sysarg_t) map_flags, (sysarg_t) flags & ~DMAMEM_FLAGS_ANONYMOUS, 86 (sysarg_t) phys, (sysarg_t) virt, 0); 86 87 } 87 88 … … 89 90 unsigned int flags, void **phys, void **virt) 90 91 { 91 *virt = as_get_mappable_page(size); 92 if (*virt == NULL) 93 return ENOMEM; 94 95 return dmamem_map(*virt, size, map_flags, 96 flags | DMAMEM_FLAGS_ANONYMOUS, phys); 92 return (int) __SYSCALL6(SYS_DMAMEM_MAP, (sysarg_t) size, 93 (sysarg_t) map_flags, (sysarg_t) flags | DMAMEM_FLAGS_ANONYMOUS, 94 (sysarg_t) phys, (sysarg_t) virt, (sysarg_t) __entry); 97 95 } 98 96 99 int dmamem_unmap(void *virt, size_t size , unsigned int flags)97 int dmamem_unmap(void *virt, size_t size) 100 98 { 101 return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, (sysarg_t) size, 102 (sysarg_t) flags); 99 return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, (sysarg_t) size, 0); 103 100 } 104 101 … … 138 135 * @param pio_addr I/O start address. 139 136 * @param size Size of the I/O region. 140 * @param use_addr Address where the final address for141 * application's PIO will be stored.137 * @param virt Virtual address for application's 138 * PIO operations. 142 139 * 143 * @return Zero on success or negative error code. 140 * @return EOK on success. 141 * @return Negative error code on failure. 144 142 * 145 143 */ 146 int pio_enable(void *pio_addr, size_t size, void ** use_addr)144 int pio_enable(void *pio_addr, size_t size, void **virt) 147 145 { 148 void *phys;149 void *virt;150 size_t offset;151 unsigned int pages;152 153 146 #ifdef IO_SPACE_BOUNDARY 154 147 if (pio_addr < IO_SPACE_BOUNDARY) { 155 * use_addr= pio_addr;148 *virt = pio_addr; 156 149 return iospace_enable(task_get_id(), pio_addr, size); 157 150 } 158 151 #endif 159 152 160 phys = (void *) ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE); 161 offset = pio_addr - phys; 162 pages = ALIGN_UP(offset + size, PAGE_SIZE) >> PAGE_WIDTH; 163 virt = as_get_mappable_page(pages << PAGE_WIDTH); 164 *use_addr = virt + offset; 165 return physmem_map(phys, virt, pages, AS_AREA_READ | AS_AREA_WRITE); 153 void *phys_frame = 154 (void *) ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE); 155 size_t offset = pio_addr - phys_frame; 156 size_t pages = SIZE2PAGES(offset + size); 157 158 void *virt_page; 159 int rc = physmem_map(phys_frame, pages, 160 AS_AREA_READ | AS_AREA_WRITE, &virt_page); 161 if (rc != EOK) 162 return rc; 163 164 *virt = virt_page + offset; 165 return EOK; 166 166 } 167 167
Note:
See TracChangeset
for help on using the changeset viewer.