memoryOperation.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * linux/arch/arm/common/vic.c
  3. *
  4. * Copyright (C) 1999 - 2003 ARM Limited
  5. * Copyright (C) 2000 Deep Blue Solutions Ltd
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/export.h>
  22. #include <linux/init.h>
  23. #include <linux/list.h>
  24. #include <linux/io.h>
  25. #include <linux/irqdomain.h>
  26. #include <linux/of.h>
  27. #include <linux/of_address.h>
  28. #include <linux/of_irq.h>
  29. #include <linux/syscore_ops.h>
  30. #include <linux/device.h>
  31. #include <linux/amba/bus.h>
  32. #include <asm/exception.h>
  33. #include <asm/mach/irq.h>
  34. #include <asm/hardware/vic.h>
  35. /**
  36. * struct vic_device - VIC PM device
  37. * @irq: The IRQ number for the base of the VIC.
  38. * @base: The register base for the VIC.
  39. * @valid_sources: A bitmask of valid interrupts
  40. * @resume_sources: A bitmask of interrupts for resume.
  41. * @resume_irqs: The IRQs enabled for resume.
  42. * @int_select: Save for VIC_INT_SELECT.
  43. * @int_enable: Save for VIC_INT_ENABLE.
  44. * @soft_int: Save for VIC_INT_SOFT.
  45. * @protect: Save for VIC_PROTECT.
  46. * @domain: The IRQ domain for the VIC.
  47. */
  48. struct vic_device {
  49. void __iomem *base;
  50. int irq;
  51. u32 valid_sources;
  52. u32 resume_sources;
  53. u32 resume_irqs;
  54. u32 int_select;
  55. u32 int_enable;
  56. u32 soft_int;
  57. u32 protect;
  58. struct irq_domain *domain;
  59. };
  60. /* we cannot allocate memory when VICs are initially registered */
  61. static struct vic_device vic_devices[CONFIG_ARM_VIC_NR];
  62. static int vic_id;
  63. /**
  64. * vic_init2 - common initialisation code
  65. * @base: Base of the VIC.
  66. *
  67. * Common initialisation code for registration
  68. * and resume.
  69. */
  70. static void vic_init2(void __iomem *base)
  71. {
  72. int i;
  73. for (i = 0; i < 16; i++) {
  74. void __iomem *reg = base + VIC_VECT_CNTL0 + (i * 4);
  75. writel(VIC_VECT_CNTL_ENABLE | i, reg);
  76. }
  77. writel(32, base + VIC_PL190_DEF_VECT_ADDR);
  78. }
  79. #ifdef CONFIG_PM
  80. static void resume_one_vic(struct vic_device *vic)
  81. {
  82. void __iomem *base = vic->base;
  83. printk(KERN_DEBUG "%s: resuming vic at %p\n", __func__, base);
  84. /* re-initialise static settings */
  85. vic_init2(base);
  86. writel(vic->int_select, base + VIC_INT_SELECT);
  87. writel(vic->protect, base + VIC_PROTECT);
  88. /* set the enabled ints and then clear the non-enabled */
  89. writel(vic->int_enable, base + VIC_INT_ENABLE);
  90. writel(~vic->int_enable, base + VIC_INT_ENABLE_CLEAR);
  91. /* and the same for the soft-int register */
  92. writel(vic->soft_int, base + VIC_INT_SOFT);
  93. writel(~vic->soft_int, base + VIC_INT_SOFT_CLEAR);
  94. }
  95. static void vic_resume(void)
  96. {
  97. int id;
  98. for (id = vic_id - 1; id >= 0; id--)
  99. resume_one_vic(vic_devices + id);
  100. }
  101. static void suspend_one_vic(struct vic_device *vic)
  102. {
  103. void __iomem *base = vic->base;
  104. printk(KERN_DEBUG "%s: suspending vic at %p\n", __func__, base);
  105. vic->int_select = readl(base + VIC_INT_SELECT);
  106. vic->int_enable = readl(base + VIC_INT_ENABLE);
  107. vic->soft_int = readl(base + VIC_INT_SOFT);
  108. vic->protect = readl(base + VIC_PROTECT);
  109. /* set the interrupts (if any) that are used for
  110. * resuming the system */
  111. writel(vic->resume_irqs, base + VIC_INT_ENABLE);
  112. writel(~vic->resume_irqs, base + VIC_INT_ENABLE_CLEAR);
  113. }
  114. static int vic_suspend(void)
  115. {
  116. int id;
  117. for (id = 0; id < vic_id; id++)
  118. suspend_one_vic(vic_devices + id);
  119. return 0;
  120. }
  121. struct syscore_ops vic_syscore_ops = {
  122. .suspend = vic_suspend,
  123. .resume = vic_resume,
  124. };
  125. /**
  126. * vic_pm_init - initicall to register VIC pm
  127. *
  128. * This is called via late_initcall() to register
  129. * the resources for the VICs due to the early
  130. * nature of the VIC's registration.
  131. */
  132. static int __init vic_pm_init(void)
  133. {
  134. if (vic_id > 0)
  135. register_syscore_ops(&vic_syscore_ops);
  136. return 0;
  137. }
  138. late_initcall(vic_pm_init);
  139. #endif /* CONFIG_PM */
  140. static struct irq_chip vic_chip;
  141. static int vic_irqdomain_map(struct irq_domain *d, unsigned int irq,
  142. irq_hw_number_t hwirq)
  143. {
  144. struct vic_device *v = d->host_data;
  145. /* Skip invalid IRQs, only register handlers for the real ones */
  146. if (!(v->valid_sources & (1 << hwirq)))
  147. return -ENOTSUPP;
  148. irq_set_chip_and_handler(irq, &vic_chip, handle_level_irq);
  149. irq_set_chip_data(irq, v->base);
  150. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  151. return 0;
  152. }
  153. static struct irq_domain_ops vic_irqdomain_ops = {
  154. .map = vic_irqdomain_map,
  155. .xlate = irq_domain_xlate_onetwocell,
  156. };
  157. /**
  158. * vic_register() - Register a VIC.
  159. * @base: The base address of the VIC.
  160. * @irq: The base IRQ for the VIC.
  161. * @valid_sources: bitmask of valid interrupts