pcidma.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (C) 2001 David J. Mckay (david.mckay@st.com)
  3. *
  4. * May be copied or modified under the terms of the GNU General Public
  5. * License. See linux/COPYING for more information.
  6. *
  7. * Dynamic DMA mapping support.
  8. */
  9. #include <linux/types.h>
  10. #include <linux/mm.h>
  11. #include <linux/string.h>
  12. #include <linux/pci.h>
  13. #include <asm/io.h>
  14. #include <asm/addrspace.h>
  15. void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
  16. dma_addr_t * dma_handle)
  17. {
  18. void *ret;
  19. int gfp = GFP_ATOMIC;
  20. ret = (void *) __get_free_pages(gfp, get_order(size));
  21. if (ret != NULL) {
  22. /* Is it neccessary to do the memset? */
  23. memset(ret, 0, size);
  24. *dma_handle = virt_to_bus(ret);
  25. }
  26. /* We must flush the cache before we pass it on to the device */
  27. flush_cache_all();
  28. return P2SEGADDR(ret);
  29. }
  30. void pci_free_consistent(struct pci_dev *hwdev, size_t size,
  31. void *vaddr, dma_addr_t dma_handle)
  32. {
  33. unsigned long p1addr=P1SEGADDR((unsigned long)vaddr);
  34. free_pages(p1addr, get_order(size));
  35. }