Changes in kernel/generic/src/ddi/ddi.c [5df1963:2c0b348] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/ddi/ddi.c
r5df1963 r2c0b348 314 314 315 315 NO_TRACE static int dmamem_map(uintptr_t virt, size_t size, unsigned int map_flags, 316 unsigned int flags, uintptr_t*phys)316 unsigned int flags, void **phys) 317 317 { 318 318 ASSERT(TASK); … … 322 322 } 323 323 324 NO_TRACE static int dmamem_map_anonymous(size_t size, uintptr_t constraint, 325 unsigned int map_flags, unsigned int flags, uintptr_t *phys, 326 uintptr_t *virt, uintptr_t bound) 324 NO_TRACE static int dmamem_map_anonymous(size_t size, unsigned int map_flags, 325 unsigned int flags, void **phys, uintptr_t *virt, uintptr_t bound) 327 326 { 328 327 ASSERT(TASK); 329 328 330 size_t frames = SIZE2FRAMES(size); 331 *phys = frame_alloc_noreserve(frames, 0, constraint); 332 if (*phys == 0) 329 size_t pages = SIZE2FRAMES(size); 330 uint8_t order; 331 332 /* We need the 2^order >= pages */ 333 if (pages == 1) 334 order = 0; 335 else 336 order = fnzb(pages - 1) + 1; 337 338 *phys = frame_alloc_noreserve(order, FRAME_DMA); 339 if (*phys == NULL) 333 340 return ENOMEM; 334 341 335 342 mem_backend_data_t backend_data; 336 backend_data.base = *phys;337 backend_data.frames = frames;343 backend_data.base = (uintptr_t) *phys; 344 backend_data.frames = pages; 338 345 339 346 if (!as_area_create(TASK->as, map_flags, size, 340 347 AS_AREA_ATTR_NONE, &phys_backend, &backend_data, virt, bound)) { 341 frame_free_noreserve( *phys, frames);348 frame_free_noreserve((uintptr_t) *phys); 342 349 return ENOMEM; 343 350 } … … 354 361 NO_TRACE static int dmamem_unmap_anonymous(uintptr_t virt) 355 362 { 356 // TODO: implement unlocking & unmap 357 return EOK; 363 // TODO: This is an ugly hack 364 as_t *as = TASK->as; 365 366 mutex_lock(&as->lock); 367 as_area_t *area = find_locked_area(as, virt); 368 if (!area) { 369 mutex_unlock(&as->lock); 370 return ENOENT; 371 } 372 frame_free_noreserve(area->backend_data.base); 373 area->backend_data.base = 0; 374 area->backend_data.frames = 0; 375 mutex_unlock(&area->lock); 376 mutex_unlock(&as->lock); 377 378 return as_area_destroy(as, virt); 358 379 } 359 380 … … 366 387 */ 367 388 368 uintptr_tphys;389 void *phys; 369 390 int rc = dmamem_map((uintptr_t) virt_ptr, size, map_flags, 370 391 flags, &phys); … … 383 404 */ 384 405 385 uintptr_t constraint; 386 int rc = copy_from_uspace(&constraint, phys_ptr, 387 sizeof(constraint)); 388 if (rc != EOK) 389 return rc; 390 391 uintptr_t phys; 406 void *phys; 392 407 uintptr_t virt = (uintptr_t) -1; 393 rc = dmamem_map_anonymous(size, constraint, map_flags, flags,408 int rc = dmamem_map_anonymous(size, map_flags, flags, 394 409 &phys, &virt, bound); 395 410 if (rc != EOK)
Note:
See TracChangeset
for help on using the changeset viewer.