mon_dma.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * The USB Monitor, inspired by Dave Harding's USBMon.
  3. *
  4. * mon_dma.c: Library which snoops on DMA areas.
  5. *
  6. * Copyright (C) 2005 Pete Zaitcev (zaitcev@redhat.com)
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/list.h>
  10. #include <linux/highmem.h>
  11. #include <asm/page.h>
  12. #include <linux/usb.h> /* Only needed for declarations in usb_mon.h */
  13. #include "usb_mon.h"
  14. /*
  15. * PC-compatibles, are, fortunately, sufficiently cache-coherent for this.
  16. */
  17. #if defined(__i386__) || defined(__x86_64__) /* CONFIG_ARCH_I386 doesn't exit */
  18. #define MON_HAS_UNMAP 1
  19. #define phys_to_page(phys) pfn_to_page((phys) >> PAGE_SHIFT)
  20. char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len)
  21. {
  22. struct page *pg;
  23. unsigned long flags;
  24. unsigned char *map;
  25. unsigned char *ptr;
  26. /*
  27. * On i386, a DMA handle is the "physical" address of a page.
  28. * In other words, the bus address is equal to physical address.
  29. * There is no IOMMU.
  30. */
  31. pg = phys_to_page(dma_addr);
  32. /*
  33. * We are called from hardware IRQs in case of callbacks.
  34. * But we can be called from softirq or process context in case
  35. * of submissions. In such case, we need to protect KM_IRQ0.
  36. */
  37. local_irq_save(flags);
  38. map = kmap_atomic(pg, KM_IRQ0);
  39. ptr = map + (dma_addr & (PAGE_SIZE-1));
  40. memcpy(dst, ptr, len);
  41. kunmap_atomic(map, KM_IRQ0);
  42. local_irq_restore(flags);
  43. return 0;
  44. }
  45. #endif /* __i386__ */
  46. #ifndef MON_HAS_UNMAP
  47. char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len)
  48. {
  49. return 'D';
  50. }
  51. #endif