system.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* Generic system definitions, based on MN10300 definitions.
  2. *
  3. * It should be possible to use these on really simple architectures,
  4. * but it serves more as a starting point for new ports.
  5. *
  6. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  7. * Written by David Howells (dhowells@redhat.com)
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public Licence
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the Licence, or (at your option) any later version.
  13. */
  14. #ifndef __ASM_GENERIC_SYSTEM_H
  15. #define __ASM_GENERIC_SYSTEM_H
  16. #ifndef __ASSEMBLY__
  17. #include <linux/types.h>
  18. #include <linux/irqflags.h>
  19. #include <asm/barrier.h>
  20. #include <asm/cmpxchg.h>
  21. struct task_struct;
  22. /* context switching is now performed out-of-line in switch_to.S */
  23. extern struct task_struct *__switch_to(struct task_struct *,
  24. struct task_struct *);
  25. #define switch_to(prev, next, last) \
  26. do { \
  27. ((last) = __switch_to((prev), (next))); \
  28. } while (0)
  29. #define arch_align_stack(x) (x)
  30. /*
  31. * we make sure local_irq_enable() doesn't cause priority inversion
  32. */
  33. /* This function doesn't exist, so you'll get a linker error
  34. * if something tries to do an invalid xchg(). */
  35. extern void __xchg_called_with_bad_pointer(void);
  36. static inline
  37. unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
  38. {
  39. unsigned long ret, flags;
  40. switch (size) {
  41. case 1:
  42. #ifdef __xchg_u8
  43. return __xchg_u8(x, ptr);
  44. #else
  45. local_irq_save(flags);
  46. ret = *(volatile u8 *)ptr;
  47. *(volatile u8 *)ptr = x;
  48. local_irq_restore(flags);
  49. return ret;
  50. #endif /* __xchg_u8 */
  51. case 2:
  52. #ifdef __xchg_u16
  53. return __xchg_u16(x, ptr);
  54. #else
  55. local_irq_save(flags);
  56. ret = *(volatile u16 *)ptr;
  57. *(volatile u16 *)ptr = x;
  58. local_irq_restore(flags);
  59. return ret;
  60. #endif /* __xchg_u16 */
  61. case 4:
  62. #ifdef __xchg_u32
  63. return __xchg_u32(x, ptr);
  64. #else
  65. local_irq_save(flags);
  66. ret = *(volatile u32 *)ptr;
  67. *(volatile u32 *)ptr = x;
  68. local_irq_restore(flags);
  69. return ret;
  70. #endif /* __xchg_u32 */
  71. #ifdef CONFIG_64BIT
  72. case 8:
  73. #ifdef __xchg_u64
  74. return __xchg_u64(x, ptr);
  75. #else
  76. local_irq_save(flags);
  77. ret = *(volatile u64 *)ptr;
  78. *(volatile u64 *)ptr = x;
  79. local_irq_restore(flags);
  80. return ret;
  81. #endif /* __xchg_u64 */
  82. #endif /* CONFIG_64BIT */
  83. default:
  84. __xchg_called_with_bad_pointer();
  85. return x;
  86. }
  87. }
  88. #define xchg(ptr, x) \
  89. ((__typeof__(*(ptr))) __xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
  90. #endif /* !__ASSEMBLY__ */
  91. #endif /* __ASM_GENERIC_SYSTEM_H */