rsrc_mgr.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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/module.h>
  15. #include <linux/kernel.h>
  16. #include <pcmcia/cs_types.h>
  17. #include <pcmcia/ss.h>
  18. #include <pcmcia/cs.h>
  19. #include <pcmcia/cistpl.h>
  20. #include "cs_internal.h"
  21. static int static_init(struct pcmcia_socket *s)
  22. {
  23. /* the good thing about SS_CAP_STATIC_MAP sockets is
  24. * that they don't need a resource database */
  25. s->resource_setup_done = 1;
  26. return 0;
  27. }
  28. struct pccard_resource_ops pccard_static_ops = {
  29. .validate_mem = NULL,
  30. .adjust_io_region = NULL,
  31. .find_io = NULL,
  32. .find_mem = NULL,
  33. .add_io = NULL,
  34. .add_mem = NULL,
  35. .init = static_init,
  36. .exit = NULL,
  37. };
  38. EXPORT_SYMBOL(pccard_static_ops);
  39. #ifdef CONFIG_PCCARD_IODYN
  40. static struct resource *
  41. make_resource(unsigned long b, unsigned long n, int flags, char *name)
  42. {
  43. struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL);
  44. if (res) {
  45. res->name = name;
  46. res->start = b;
  47. res->end = b + n - 1;
  48. res->flags = flags;
  49. }
  50. return res;
  51. }
  52. struct pcmcia_align_data {
  53. unsigned long mask;
  54. unsigned long offset;
  55. };
  56. static resource_size_t pcmcia_align(void *align_data,
  57. const struct resource *res,
  58. resource_size_t size, resource_size_t align)
  59. {
  60. struct pcmcia_align_data *data = align_data;
  61. resource_size_t start;
  62. start = (res->start & ~data->mask) + data->offset;
  63. if (start < res->start)
  64. start += data->mask + 1;
  65. #ifdef CONFIG_X86
  66. if (res->flags & IORESOURCE_IO) {
  67. if (start & 0x300)
  68. start = (start + 0x3ff) & ~0x3ff;
  69. }
  70. #endif
  71. #ifdef CONFIG_M68K
  72. if (res->flags & IORESOURCE_IO) {
  73. if ((res->start + size - 1) >= 1024)
  74. start = res->end;
  75. }
  76. #endif
  77. return start;
  78. }
  79. static int iodyn_adjust_io_region(struct resource *res, unsigned long r_start,
  80. unsigned long r_end, struct pcmcia_socket *s)
  81. {
  82. return adjust_resource(res, r_start, r_end - r_start + 1);
  83. }
  84. static struct resource *iodyn_find_io_region(unsigned long base, int num,
  85. unsigned long align, struct pcmcia_socket *s)
  86. {
  87. struct resource *res = make_resource(0, num, IORESOURCE_IO,
  88. dev_name(&s->dev));
  89. struct pcmcia_align_data data;
  90. unsigned long min = base;
  91. int ret;
  92. if (align == 0)
  93. align = 0x10000;
  94. data.mask = align - 1;
  95. data.offset = base & data.mask;
  96. #ifdef CONFIG_PCI
  97. if (s->cb_dev) {
  98. ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1,
  99. min, 0, pcmcia_align, &data);
  100. } else
  101. #endif
  102. ret = allocate_resource(&ioport_resource, res, num, min, ~0UL,
  103. 1, pcmcia_align, &data);
  104. if (ret != 0) {
  105. kfree(res);
  106. res = NULL;
  107. }
  108. return res;
  109. }
  110. struct pccard_resource_ops pccard_iodyn_ops = {
  111. .validate_mem = NULL,
  112. .adjust_io_region = iodyn_adjust_io_region,
  113. .find_io = iodyn_find_io_region,
  114. .find_mem = NULL,
  115. .add_io = NULL,
  116. .add_mem = NULL,
  117. .init = static_init,
  118. .exit = NULL,
  119. };
  120. EXPORT_SYMBOL(pccard_iodyn_ops);
  121. #endif /* CONFIG_PCCARD_IODYN */