xip.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * MTD primitives for XIP support
  3. *
  4. * Author: Nicolas Pitre
  5. * Created: Nov 2, 2004
  6. * Copyright: (C) 2004 MontaVista Software, Inc.
  7. *
  8. * This XIP support for MTD has been loosely inspired
  9. * by an earlier patch authored by David Woodhouse.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. *
  15. * $Id: xip.h,v 1.2 2004/12/01 15:49:10 nico Exp $
  16. */
  17. #ifndef __LINUX_MTD_XIP_H__
  18. #define __LINUX_MTD_XIP_H__
  19. #include <linux/config.h>
  20. #ifdef CONFIG_MTD_XIP
  21. /*
  22. * Function that are modifying the flash state away from array mode must
  23. * obviously not be running from flash. The __xipram is therefore marking
  24. * those functions so they get relocated to ram.
  25. */
  26. #define __xipram __attribute__ ((__section__ (".data")))
  27. /*
  28. * We really don't want gcc to guess anything.
  29. * We absolutely _need_ proper inlining.
  30. */
  31. #include <linux/compiler.h>
  32. /*
  33. * Each architecture has to provide the following macros. They must access
  34. * the hardware directly and not rely on any other (XIP) functions since they
  35. * won't be available when used (flash not in array mode).
  36. *
  37. * xip_irqpending()
  38. *
  39. * return non zero when any hardware interrupt is pending.
  40. *
  41. * xip_currtime()
  42. *
  43. * return a platform specific time reference to be used with
  44. * xip_elapsed_since().
  45. *
  46. * xip_elapsed_since(x)
  47. *
  48. * return in usecs the elapsed timebetween now and the reference x as
  49. * returned by xip_currtime().
  50. *
  51. * note 1: convertion to usec can be approximated, as long as the
  52. * returned value is <= the real elapsed time.
  53. * note 2: this should be able to cope with a few seconds without
  54. * overflowing.
  55. */
  56. #if defined(CONFIG_ARCH_SA1100) || defined(CONFIG_ARCH_PXA)
  57. #include <asm/hardware.h>
  58. #ifdef CONFIG_ARCH_PXA
  59. #include <asm/arch/pxa-regs.h>
  60. #endif
  61. #define xip_irqpending() (ICIP & ICMR)
  62. /* we sample OSCR and convert desired delta to usec (1/4 ~= 1000000/3686400) */
  63. #define xip_currtime() (OSCR)
  64. #define xip_elapsed_since(x) (signed)((OSCR - (x)) / 4)
  65. #else
  66. #warning "missing IRQ and timer primitives for XIP MTD support"
  67. #warning "some of the XIP MTD support code will be disabled"
  68. #warning "your system will therefore be unresponsive when writing or erasing flash"
  69. #define xip_irqpending() (0)
  70. #define xip_currtime() (0)
  71. #define xip_elapsed_since(x) (0)
  72. #endif
  73. /*
  74. * xip_cpu_idle() is used when waiting for a delay equal or larger than
  75. * the system timer tick period. This should put the CPU into idle mode
  76. * to save power and to be woken up only when some interrupts are pending.
  77. * As above, this should not rely upon standard kernel code.
  78. */
  79. #if defined(CONFIG_CPU_XSCALE)
  80. #define xip_cpu_idle() asm volatile ("mcr p14, 0, %0, c7, c0, 0" :: "r" (1))
  81. #else
  82. #define xip_cpu_idle() do { } while (0)
  83. #endif
  84. #else
  85. #define __xipram
  86. #endif /* CONFIG_MTD_XIP */
  87. #endif /* __LINUX_MTD_XIP_H__ */