rsrc_mgr.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * rsrc_mgr.c -- Resource management routines and/or wrappers
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * The initial developer of the original code is David A. Hinds
  9. * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
  10. * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  11. *
  12. * (C) 1999 David A. Hinds
  13. */
  14. #include <linux/config.h>
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <pcmcia/cs_types.h>
  18. #include <pcmcia/ss.h>
  19. #include <pcmcia/cs.h>
  20. #include "cs_internal.h"
  21. #ifdef CONFIG_PCMCIA_PROBE
  22. static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
  23. {
  24. int irq;
  25. u32 mask;
  26. irq = adj->resource.irq.IRQ;
  27. if ((irq < 0) || (irq > 15))
  28. return CS_BAD_IRQ;
  29. if (adj->Action != REMOVE_MANAGED_RESOURCE)
  30. return 0;
  31. mask = 1 << irq;
  32. if (!(s->irq_mask & mask))
  33. return 0;
  34. s->irq_mask &= ~mask;
  35. return 0;
  36. }
  37. #else
  38. static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
  39. return CS_SUCCESS;
  40. }
  41. #endif
  42. int pcmcia_adjust_resource_info(adjust_t *adj)
  43. {
  44. struct pcmcia_socket *s;
  45. int ret = CS_UNSUPPORTED_FUNCTION;
  46. unsigned long flags;
  47. down_read(&pcmcia_socket_list_rwsem);
  48. list_for_each_entry(s, &pcmcia_socket_list, socket_list) {
  49. if (adj->Resource == RES_IRQ)
  50. ret = adjust_irq(s, adj);
  51. else if (s->resource_ops->adjust_resource) {
  52. /* you can't use the old interface if the new
  53. * one was used before */
  54. spin_lock_irqsave(&s->lock, flags);
  55. if ((s->resource_setup_new) &&
  56. !(s->resource_setup_old)) {
  57. spin_unlock_irqrestore(&s->lock, flags);
  58. continue;
  59. } else if (!(s->resource_setup_old))
  60. s->resource_setup_old = 1;
  61. spin_unlock_irqrestore(&s->lock, flags);
  62. ret = s->resource_ops->adjust_resource(s, adj);
  63. if (!ret) {
  64. /* as there's no way we know this is the
  65. * last call to adjust_resource_info, we
  66. * always need to assume this is the latest
  67. * one... */
  68. spin_lock_irqsave(&s->lock, flags);
  69. s->resource_setup_done = 1;
  70. spin_unlock_irqrestore(&s->lock, flags);
  71. }
  72. }
  73. }
  74. up_read(&pcmcia_socket_list_rwsem);
  75. return (ret);
  76. }
  77. EXPORT_SYMBOL(pcmcia_adjust_resource_info);
  78. void pcmcia_validate_mem(struct pcmcia_socket *s)
  79. {
  80. if (s->resource_ops->validate_mem)
  81. s->resource_ops->validate_mem(s);
  82. }
  83. EXPORT_SYMBOL(pcmcia_validate_mem);
  84. int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start,
  85. unsigned long r_end, struct pcmcia_socket *s)
  86. {
  87. if (s->resource_ops->adjust_io_region)
  88. return s->resource_ops->adjust_io_region(res, r_start, r_end, s);
  89. return -ENOMEM;
  90. }
  91. EXPORT_SYMBOL(pcmcia_adjust_io_region);
  92. struct resource *pcmcia_find_io_region(unsigned long base, int num,
  93. unsigned long align, struct pcmcia_socket *s)
  94. {
  95. if (s->resource_ops->find_io)
  96. return s->resource_ops->find_io(base, num, align, s);
  97. return NULL;
  98. }
  99. EXPORT_SYMBOL(pcmcia_find_io_region);
  100. struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
  101. int low, struct pcmcia_socket *s)
  102. {
  103. if (s->resource_ops->find_mem)
  104. return s->resource_ops->find_mem(base, num, align, low, s);
  105. return NULL;
  106. }
  107. EXPORT_SYMBOL(pcmcia_find_mem_region);
  108. void release_resource_db(struct pcmcia_socket *s)
  109. {
  110. if (s->resource_ops->exit)
  111. s->resource_ops->exit(s);
  112. }
  113. static int static_init(struct pcmcia_socket *s)
  114. {
  115. unsigned long flags;
  116. /* the good thing about SS_CAP_STATIC_MAP sockets is
  117. * that they don't need a resource database */
  118. spin_lock_irqsave(&s->lock, flags);
  119. s->resource_setup_done = 1;
  120. spin_unlock_irqrestore(&s->lock, flags);
  121. return 0;
  122. }
  123. struct pccard_resource_ops pccard_static_ops = {
  124. .validate_mem = NULL,
  125. .adjust_io_region = NULL,
  126. .find_io = NULL,
  127. .find_mem = NULL,
  128. .adjust_resource = NULL,
  129. .init = static_init,
  130. .exit = NULL,
  131. };
  132. EXPORT_SYMBOL(pccard_static_ops);