proto_busdma.c (f94594b37a145b9b3e9ff31af2cd1dc3de8aa4d4) | proto_busdma.c (9f011bca829751ed3552ac94fe7c865d75fabfc4) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 2015 Marcel Moolenaar | 2 * Copyright (c) 2015, 2019 Marcel Moolenaar |
3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 24 unchanged lines hidden (view full) --- 35#include <sys/conf.h> 36#include <sys/kernel.h> 37#include <sys/malloc.h> 38#include <sys/module.h> 39#include <sys/proc.h> 40#include <sys/queue.h> 41#include <sys/rman.h> 42#include <sys/sbuf.h> | 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 24 unchanged lines hidden (view full) --- 35#include <sys/conf.h> 36#include <sys/kernel.h> 37#include <sys/malloc.h> 38#include <sys/module.h> 39#include <sys/proc.h> 40#include <sys/queue.h> 41#include <sys/rman.h> 42#include <sys/sbuf.h> |
43#include <sys/sx.h> |
|
43#include <sys/uio.h> 44#include <vm/vm.h> 45#include <vm/pmap.h> 46#include <vm/vm_map.h> 47 48#include <dev/proto/proto.h> 49#include <dev/proto/proto_dev.h> 50#include <dev/proto/proto_busdma.h> --- 299 unchanged lines hidden (view full) --- 350} 351 352struct proto_busdma * 353proto_busdma_attach(struct proto_softc *sc) 354{ 355 struct proto_busdma *busdma; 356 357 busdma = malloc(sizeof(*busdma), M_PROTO_BUSDMA, M_WAITOK | M_ZERO); | 44#include <sys/uio.h> 45#include <vm/vm.h> 46#include <vm/pmap.h> 47#include <vm/vm_map.h> 48 49#include <dev/proto/proto.h> 50#include <dev/proto/proto_dev.h> 51#include <dev/proto/proto_busdma.h> --- 299 unchanged lines hidden (view full) --- 351} 352 353struct proto_busdma * 354proto_busdma_attach(struct proto_softc *sc) 355{ 356 struct proto_busdma *busdma; 357 358 busdma = malloc(sizeof(*busdma), M_PROTO_BUSDMA, M_WAITOK | M_ZERO); |
359 sx_init(&busdma->sxlck, "proto-busdma"); |
|
358 return (busdma); 359} 360 361int 362proto_busdma_detach(struct proto_softc *sc, struct proto_busdma *busdma) 363{ 364 365 proto_busdma_cleanup(sc, busdma); | 360 return (busdma); 361} 362 363int 364proto_busdma_detach(struct proto_softc *sc, struct proto_busdma *busdma) 365{ 366 367 proto_busdma_cleanup(sc, busdma); |
368 sx_destroy(&busdma->sxlck); |
|
366 free(busdma, M_PROTO_BUSDMA); 367 return (0); 368} 369 370int 371proto_busdma_cleanup(struct proto_softc *sc, struct proto_busdma *busdma) 372{ 373 struct proto_md *md, *md1; 374 struct proto_tag *tag, *tag1; 375 | 369 free(busdma, M_PROTO_BUSDMA); 370 return (0); 371} 372 373int 374proto_busdma_cleanup(struct proto_softc *sc, struct proto_busdma *busdma) 375{ 376 struct proto_md *md, *md1; 377 struct proto_tag *tag, *tag1; 378 |
379 sx_xlock(&busdma->sxlck); |
|
376 LIST_FOREACH_SAFE(md, &busdma->mds, mds, md1) 377 proto_busdma_md_destroy_internal(busdma, md); 378 LIST_FOREACH_SAFE(tag, &busdma->tags, tags, tag1) 379 proto_busdma_tag_destroy(busdma, tag); | 380 LIST_FOREACH_SAFE(md, &busdma->mds, mds, md1) 381 proto_busdma_md_destroy_internal(busdma, md); 382 LIST_FOREACH_SAFE(tag, &busdma->tags, tags, tag1) 383 proto_busdma_tag_destroy(busdma, tag); |
384 sx_xunlock(&busdma->sxlck); |
|
380 return (0); 381} 382 383int 384proto_busdma_ioctl(struct proto_softc *sc, struct proto_busdma *busdma, 385 struct proto_ioc_busdma *ioc, struct thread *td) 386{ 387 struct proto_tag *tag; 388 struct proto_md *md; 389 int error; 390 | 385 return (0); 386} 387 388int 389proto_busdma_ioctl(struct proto_softc *sc, struct proto_busdma *busdma, 390 struct proto_ioc_busdma *ioc, struct thread *td) 391{ 392 struct proto_tag *tag; 393 struct proto_md *md; 394 int error; 395 |
396 sx_xlock(&busdma->sxlck); 397 |
|
391 error = 0; 392 switch (ioc->request) { 393 case PROTO_IOC_BUSDMA_TAG_CREATE: 394 busdma->bd_roottag = bus_get_dma_tag(sc->sc_dev); 395 error = proto_busdma_tag_create(busdma, NULL, ioc); 396 break; 397 case PROTO_IOC_BUSDMA_TAG_DERIVE: 398 tag = proto_busdma_tag_lookup(busdma, ioc->key); --- 66 unchanged lines hidden (view full) --- 465 break; 466 } 467 error = proto_busdma_sync(busdma, md, ioc); 468 break; 469 default: 470 error = EINVAL; 471 break; 472 } | 398 error = 0; 399 switch (ioc->request) { 400 case PROTO_IOC_BUSDMA_TAG_CREATE: 401 busdma->bd_roottag = bus_get_dma_tag(sc->sc_dev); 402 error = proto_busdma_tag_create(busdma, NULL, ioc); 403 break; 404 case PROTO_IOC_BUSDMA_TAG_DERIVE: 405 tag = proto_busdma_tag_lookup(busdma, ioc->key); --- 66 unchanged lines hidden (view full) --- 472 break; 473 } 474 error = proto_busdma_sync(busdma, md, ioc); 475 break; 476 default: 477 error = EINVAL; 478 break; 479 } |
480 481 sx_xunlock(&busdma->sxlck); 482 |
|
473 return (error); 474} 475 476int 477proto_busdma_mmap_allowed(struct proto_busdma *busdma, vm_paddr_t physaddr) 478{ 479 struct proto_md *md; | 483 return (error); 484} 485 486int 487proto_busdma_mmap_allowed(struct proto_busdma *busdma, vm_paddr_t physaddr) 488{ 489 struct proto_md *md; |
490 int result; |
|
480 | 491 |
492 sx_xlock(&busdma->sxlck); 493 494 result = 0; |
|
481 LIST_FOREACH(md, &busdma->mds, mds) { 482 if (physaddr >= trunc_page(md->physaddr) && | 495 LIST_FOREACH(md, &busdma->mds, mds) { 496 if (physaddr >= trunc_page(md->physaddr) && |
483 physaddr <= trunc_page(md->physaddr + md->tag->maxsz)) 484 return (1); | 497 physaddr <= trunc_page(md->physaddr + md->tag->maxsz)) { 498 result = 1; 499 break; 500 } |
485 } | 501 } |
486 return (0); | 502 503 sx_xunlock(&busdma->sxlck); 504 505 return (result); |
487} | 506} |