devmap.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * promdevmap.c: Map device/IO areas to virtual addresses.
  3. *
  4. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5. */
  6. #include <linux/types.h>
  7. #include <linux/kernel.h>
  8. #include <linux/sched.h>
  9. #include <asm/openprom.h>
  10. #include <asm/oplib.h>
  11. extern void restore_current(void);
  12. /* Just like the routines in palloc.c, these should not be used
  13. * by the kernel at all. Bootloader facility mainly. And again,
  14. * this is only available on V2 proms and above.
  15. */
  16. /* Map physical device address 'paddr' in IO space 'ios' of size
  17. * 'num_bytes' to a virtual address, with 'vhint' being a hint to
  18. * the prom as to where you would prefer the mapping. We return
  19. * where the prom actually mapped it.
  20. */
  21. char *
  22. prom_mapio(char *vhint, int ios, unsigned int paddr, unsigned int num_bytes)
  23. {
  24. unsigned long flags;
  25. char *ret;
  26. spin_lock_irqsave(&prom_lock, flags);
  27. if((num_bytes == 0) || (paddr == 0)) ret = (char *) 0x0;
  28. else
  29. ret = (*(romvec->pv_v2devops.v2_dumb_mmap))(vhint, ios, paddr,
  30. num_bytes);
  31. restore_current();
  32. spin_unlock_irqrestore(&prom_lock, flags);
  33. return ret;
  34. }
  35. /* Unmap an IO/device area that was mapped using the above routine. */
  36. void
  37. prom_unmapio(char *vaddr, unsigned int num_bytes)
  38. {
  39. unsigned long flags;
  40. if(num_bytes == 0x0) return;
  41. spin_lock_irqsave(&prom_lock, flags);
  42. (*(romvec->pv_v2devops.v2_dumb_munmap))(vaddr, num_bytes);
  43. restore_current();
  44. spin_unlock_irqrestore(&prom_lock, flags);
  45. return;
  46. }