Changeset c6ae4c2 in mainline for kernel/generic/src/ddi/ddi.c
- Timestamp:
- 2011-12-16T21:12:52Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c8751452
- Parents:
- e2718e1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/ddi/ddi.c
re2718e1 rc6ae4c2 45 45 #include <mm/frame.h> 46 46 #include <mm/as.h> 47 #include <mm/page.h> 47 48 #include <synch/mutex.h> 48 49 #include <syscall/copy.h> … … 52 53 #include <errno.h> 53 54 #include <trace.h> 55 #include <bitops.h> 54 56 55 57 /** This lock protects the parea_btree. */ … … 87 89 /** Map piece of physical memory into virtual address space of current task. 88 90 * 89 * @param p fPhysical address of the starting frame.90 * @param v pVirtual address of the starting page.91 * @param phys Physical address of the starting frame. 92 * @param virt Virtual address of the starting page. 91 93 * @param pages Number of pages to map. 92 94 * @param flags Address space area flags for the mapping. 93 95 * 94 * @return 0 on success, EPERM if the caller lacks capabilities to use this 95 * syscall, EBADMEM if pf or vf is not page aligned, ENOENT if there 96 * is no task matching the specified ID or the physical address space 97 * is not enabled for mapping and ENOMEM if there was a problem in 98 * creating address space area. 99 * 100 */ 101 NO_TRACE static int ddi_physmem_map(uintptr_t pf, uintptr_t vp, size_t pages, 96 * @return EOK on success. 97 * @return EPERM if the caller lacks capabilities to use this syscall. 98 * @return EBADMEM if phys or virt is not page aligned. 99 * @return ENOENT if there is no task matching the specified ID or 100 * the physical address space is not enabled for mapping. 101 * @return ENOMEM if there was a problem in creating address space area. 102 * 103 */ 104 NO_TRACE static int ddi_physmem_map(uintptr_t phys, uintptr_t virt, size_t pages, 102 105 unsigned int flags) 103 106 { 104 107 ASSERT(TASK); 105 108 106 if ((p f% FRAME_SIZE) != 0)109 if ((phys % FRAME_SIZE) != 0) 107 110 return EBADMEM; 108 111 109 if ((v p% PAGE_SIZE) != 0)112 if ((virt % PAGE_SIZE) != 0) 110 113 return EBADMEM; 111 114 … … 118 121 119 122 mem_backend_data_t backend_data; 120 backend_data.base = p f;123 backend_data.base = phys; 121 124 backend_data.frames = pages; 122 125 … … 129 132 btree_node_t *nodep; 130 133 parea_t *parea = (parea_t *) btree_search(&parea_btree, 131 (btree_key_t) p f, &nodep);134 (btree_key_t) phys, &nodep); 132 135 133 136 if ((parea != NULL) && (parea->frames >= pages)) { … … 149 152 150 153 irq_spinlock_lock(&zones.lock, true); 151 size_t znum = find_zone(ADDR2PFN(p f), pages, 0);154 size_t znum = find_zone(ADDR2PFN(phys), pages, 0); 152 155 153 156 if (znum == (size_t) -1) { … … 182 185 183 186 map: 184 if (!as_area_create(TASK->as, flags, pages * PAGE_SIZE, vp,187 if (!as_area_create(TASK->as, flags, FRAMES2SIZE(pages), virt, 185 188 AS_AREA_ATTR_NONE, &phys_backend, &backend_data)) { 186 189 /* … … 253 256 /** Wrapper for SYS_PHYSMEM_MAP syscall. 254 257 * 255 * @param phys _basePhysical base address to map256 * @param virt _baseDestination virtual address258 * @param phys Physical base address to map 259 * @param virt Destination virtual address 257 260 * @param pages Number of pages 258 261 * @param flags Flags of newly mapped pages … … 261 264 * 262 265 */ 263 sysarg_t sys_physmem_map( sysarg_t phys_base, sysarg_t virt_base,264 s ysarg_t pages, sysarg_t flags)265 { 266 return (sysarg_t) ddi_physmem_map(ALIGN_DOWN((uintptr_t) phys_base,267 FRAME_SIZE), ALIGN_DOWN((uintptr_t) virt_base, PAGE_SIZE),268 (size_t) pages, (int)flags);266 sysarg_t sys_physmem_map(uintptr_t phys, uintptr_t virt, 267 size_t pages, unsigned int flags) 268 { 269 return (sysarg_t) 270 ddi_physmem_map(ALIGN_DOWN(phys, FRAME_SIZE), 271 ALIGN_DOWN(virt, PAGE_SIZE), pages, flags); 269 272 } 270 273 … … 287 290 } 288 291 292 NO_TRACE static int dmamem_map(uintptr_t virt, size_t size, 293 unsigned int map_flags, unsigned int flags, void **phys) 294 { 295 ASSERT(TASK); 296 297 if ((flags & DMAMEM_FLAGS_ANONYMOUS) == 0) { 298 // TODO: implement locking of non-anonymous mapping 299 return page_find_mapping(virt, phys); 300 } else { 301 // TODO: implement locking 302 303 if ((virt % PAGE_SIZE) != 0) 304 return EBADMEM; 305 306 size_t pages = SIZE2FRAMES(size); 307 uint8_t order; 308 309 /* We need the 2^order >= pages */ 310 if (pages == 1) 311 order = 0; 312 else 313 order = fnzb(pages - 1) + 1; 314 315 *phys = frame_alloc_noreserve(order, 0); 316 if (*phys == NULL) 317 return ENOMEM; 318 319 mem_backend_data_t backend_data; 320 backend_data.base = (uintptr_t) *phys; 321 backend_data.frames = pages; 322 323 if (!as_area_create(TASK->as, map_flags, size, virt, 324 AS_AREA_ATTR_NONE, &phys_backend, &backend_data)) { 325 frame_free_noreserve((uintptr_t) *phys); 326 return ENOMEM; 327 } 328 329 return EOK; 330 } 331 } 332 333 NO_TRACE static int dmamem_unmap(uintptr_t virt, size_t size, 334 unsigned int flags) 335 { 336 // TODO: implement unlocking & unmap 337 return EOK; 338 } 339 340 sysarg_t sys_dmamem_map(uintptr_t virt, size_t size, unsigned int map_flags, 341 unsigned int flags, void *phys_ptr) 342 { 343 void *phys; 344 int rc = dmamem_map(virt, size, map_flags, flags, &phys); 345 if (rc != EOK) 346 return rc; 347 348 rc = copy_to_uspace(phys_ptr, &phys, sizeof(phys)); 349 if (rc != EOK) { 350 dmamem_unmap(virt, size, flags); 351 return rc; 352 } 353 354 return EOK; 355 } 356 357 sysarg_t sys_dmamem_unmap(uintptr_t virt, size_t size, unsigned int flags) 358 { 359 return dmamem_unmap(virt, size, flags); 360 } 361 289 362 /** @} 290 363 */
Note:
See TracChangeset
for help on using the changeset viewer.