io.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * DaVinci I/O mapping code
  3. *
  4. * Copyright (C) 2005-2006 Texas Instruments
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/io.h>
  14. #include <asm/tlb.h>
  15. #include <asm/memory.h>
  16. #include <asm/mach/map.h>
  17. #include <mach/clock.h>
  18. extern void davinci_check_revision(void);
  19. /*
  20. * The machine specific code may provide the extra mapping besides the
  21. * default mapping provided here.
  22. */
  23. static struct map_desc davinci_io_desc[] __initdata = {
  24. {
  25. .virtual = IO_VIRT,
  26. .pfn = __phys_to_pfn(IO_PHYS),
  27. .length = IO_SIZE,
  28. .type = MT_DEVICE
  29. },
  30. };
  31. void __init davinci_map_common_io(void)
  32. {
  33. iotable_init(davinci_io_desc, ARRAY_SIZE(davinci_io_desc));
  34. /* Normally devicemaps_init() would flush caches and tlb after
  35. * mdesc->map_io(), but we must also do it here because of the CPU
  36. * revision check below.
  37. */
  38. local_flush_tlb_all();
  39. flush_cache_all();
  40. /* We want to check CPU revision early for cpu_is_xxxx() macros.
  41. * IO space mapping must be initialized before we can do that.
  42. */
  43. davinci_check_revision();
  44. }
  45. #define BETWEEN(p, st, sz) ((p) >= (st) && (p) < ((st) + (sz)))
  46. #define XLATE(p, pst, vst) ((void __iomem *)((p) - (pst) + (vst)))
  47. /*
  48. * Intercept ioremap() requests for addresses in our fixed mapping regions.
  49. */
  50. void __iomem *davinci_ioremap(unsigned long p, size_t size, unsigned int type)
  51. {
  52. if (BETWEEN(p, IO_PHYS, IO_SIZE))
  53. return XLATE(p, IO_PHYS, IO_VIRT);
  54. return __arm_ioremap(p, size, type);
  55. }
  56. EXPORT_SYMBOL(davinci_ioremap);
  57. void davinci_iounmap(volatile void __iomem *addr)
  58. {
  59. unsigned long virt = (unsigned long)addr;
  60. if (virt >= VMALLOC_START && virt < VMALLOC_END)
  61. __iounmap(addr);
  62. }
  63. EXPORT_SYMBOL(davinci_iounmap);