mon_dma.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #ifdef __i386__ /* CONFIG_ARCH_I386 does not exit */
  15. #define MON_HAS_UNMAP 1
  16. #define phys_to_page(phys) pfn_to_page((phys) >> PAGE_SHIFT)
  17. char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len)
  18. {
  19. struct page *pg;
  20. unsigned long flags;
  21. unsigned char *map;
  22. unsigned char *ptr;
  23. /*
  24. * On i386, a DMA handle is the "physical" address of a page.
  25. * In other words, the bus address is equal to physical address.
  26. * There is no IOMMU.
  27. */
  28. pg = phys_to_page(dma_addr);
  29. /*
  30. * We are called from hardware IRQs in case of callbacks.
  31. * But we can be called from softirq or process context in case
  32. * of submissions. In such case, we need to protect KM_IRQ0.
  33. */
  34. local_irq_save(flags);
  35. map = kmap_atomic(pg, KM_IRQ0);
  36. ptr = map + (dma_addr & (PAGE_SIZE-1));
  37. memcpy(dst, ptr, len);
  38. kunmap_atomic(map, KM_IRQ0);
  39. local_irq_restore(flags);
  40. return 0;
  41. }
  42. #endif /* __i386__ */
  43. #ifndef MON_HAS_UNMAP
  44. char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len)
  45. {
  46. return 'D';
  47. }
  48. #endif