tc.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * TURBOchannel bus services.
  3. *
  4. * Copyright (c) Harald Koerfgen, 1998
  5. * Copyright (c) 2001, 2003, 2005, 2006 Maciej W. Rozycki
  6. * Copyright (c) 2005 James Simmons
  7. *
  8. * This file is subject to the terms and conditions of the GNU
  9. * General Public License. See the file "COPYING" in the main
  10. * directory of this archive for more details.
  11. */
  12. #include <linux/compiler.h>
  13. #include <linux/errno.h>
  14. #include <linux/init.h>
  15. #include <linux/ioport.h>
  16. #include <linux/kernel.h>
  17. #include <linux/list.h>
  18. #include <linux/module.h>
  19. #include <linux/slab.h>
  20. #include <linux/string.h>
  21. #include <linux/tc.h>
  22. #include <linux/types.h>
  23. #include <asm/io.h>
  24. static struct tc_bus tc_bus = {
  25. .name = "TURBOchannel",
  26. };
  27. /*
  28. * Probing for TURBOchannel modules.
  29. */
  30. static void __init tc_bus_add_devices(struct tc_bus *tbus)
  31. {
  32. resource_size_t slotsize = tbus->info.slot_size << 20;
  33. resource_size_t extslotsize = tbus->ext_slot_size;
  34. resource_size_t slotaddr;
  35. resource_size_t extslotaddr;
  36. resource_size_t devsize;
  37. void __iomem *module;
  38. struct tc_dev *tdev;
  39. int i, slot, err;
  40. u8 pattern[4];
  41. long offset;
  42. for (slot = 0; slot < tbus->num_tcslots; slot++) {
  43. slotaddr = tbus->slot_base + slot * slotsize;
  44. extslotaddr = tbus->ext_slot_base + slot * extslotsize;
  45. module = ioremap_nocache(slotaddr, slotsize);
  46. BUG_ON(!module);
  47. offset = TC_OLDCARD;
  48. err = 0;
  49. err |= tc_preadb(pattern + 0, module + offset + TC_PATTERN0);
  50. err |= tc_preadb(pattern + 1, module + offset + TC_PATTERN1);
  51. err |= tc_preadb(pattern + 2, module + offset + TC_PATTERN2);
  52. err |= tc_preadb(pattern + 3, module + offset + TC_PATTERN3);
  53. if (err)
  54. goto out_err;
  55. if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
  56. pattern[2] != 0xaa || pattern[3] != 0xff) {
  57. offset = TC_NEWCARD;
  58. err = 0;
  59. err |= tc_preadb(pattern + 0,
  60. module + offset + TC_PATTERN0);
  61. err |= tc_preadb(pattern + 1,
  62. module + offset + TC_PATTERN1);
  63. err |= tc_preadb(pattern + 2,
  64. module + offset + TC_PATTERN2);
  65. err |= tc_preadb(pattern + 3,
  66. module + offset + TC_PATTERN3);
  67. if (err)
  68. goto out_err;
  69. }
  70. if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
  71. pattern[2] != 0xaa || pattern[3] != 0xff)
  72. goto out_err;
  73. /* Found a board, allocate it an entry in the list */
  74. tdev = kzalloc(sizeof(*tdev), GFP_KERNEL);
  75. if (!tdev) {
  76. pr_err("tc%x: unable to allocate tc_dev\n", slot);
  77. goto out_err;
  78. }
  79. dev_set_name(&tdev->dev, "tc%x", slot);
  80. tdev->bus = tbus;
  81. tdev->dev.parent = &tbus->dev;
  82. tdev->dev.bus = &tc_bus_type;
  83. tdev->slot = slot;
  84. for (i = 0; i < 8; i++) {
  85. tdev->firmware[i] =
  86. readb(module + offset + TC_FIRM_VER + 4 * i);
  87. tdev->vendor[i] =
  88. readb(module + offset + TC_VENDOR + 4 * i);
  89. tdev->name[i] =
  90. readb(module + offset + TC_MODULE + 4 * i);
  91. }
  92. tdev->firmware[8] = 0;
  93. tdev->vendor[8] = 0;
  94. tdev->name[8] = 0;
  95. pr_info("%s: %s %s %s\n", dev_name(&tdev->dev), tdev->vendor,
  96. tdev->name, tdev->firmware);
  97. devsize = readb(module + offset + TC_SLOT_SIZE);
  98. devsize <<= 22;
  99. if (devsize <= slotsize) {
  100. tdev->resource.start = slotaddr;
  101. tdev->resource.end = slotaddr + devsize - 1;
  102. } else if (devsize <= extslotsize) {
  103. tdev->resource.start = extslotaddr;
  104. tdev->resource.end = extslotaddr + devsize - 1;
  105. } else {
  106. pr_err("%s: Cannot provide slot space "
  107. "(%ldMiB required, up to %ldMiB supported)\n",
  108. dev_name(&tdev->dev), (long)(devsize >> 20),
  109. (long)(max(slotsize, extslotsize) >> 20));
  110. kfree(tdev);
  111. goto out_err;
  112. }
  113. tdev->resource.name = tdev->name;
  114. tdev->resource.flags = IORESOURCE_MEM;
  115. tc_device_get_irq(tdev);
  116. if (device_register(&tdev->dev)) {
  117. put_device(&tdev->dev);
  118. goto out_err;
  119. }
  120. list_add_tail(&tdev->node, &tbus->devices);
  121. out_err:
  122. iounmap(module);
  123. }
  124. }
  125. /*
  126. * The main entry.
  127. */
  128. static int __init tc_init(void)
  129. {
  130. /* Initialize the TURBOchannel bus */
  131. if (tc_bus_get_info(&tc_bus))
  132. goto out_err;
  133. INIT_LIST_HEAD(&tc_bus.devices);
  134. dev_set_name(&tc_bus.dev, "tc");
  135. if (device_register(&tc_bus.dev))
  136. goto out_err_device;
  137. if (tc_bus.info.slot_size) {
  138. unsigned int tc_clock = tc_get_speed(&tc_bus) / 100000;
  139. pr_info("tc: TURBOchannel rev. %d at %d.%d MHz "
  140. "(with%s parity)\n", tc_bus.info.revision,
  141. tc_clock / 10, tc_clock % 10,
  142. tc_bus.info.parity ? "" : "out");
  143. tc_bus.resource[0].start = tc_bus.slot_base;
  144. tc_bus.resource[0].end = tc_bus.slot_base +
  145. (tc_bus.info.slot_size << 20) *
  146. tc_bus.num_tcslots - 1;
  147. tc_bus.resource[0].name = tc_bus.name;
  148. tc_bus.resource[0].flags = IORESOURCE_MEM;
  149. if (request_resource(&iomem_resource,
  150. &tc_bus.resource[0]) < 0) {
  151. pr_err("tc: Cannot reserve resource\n");
  152. goto out_err_device;
  153. }
  154. if (tc_bus.ext_slot_size) {
  155. tc_bus.resource[1].start = tc_bus.ext_slot_base;
  156. tc_bus.resource[1].end = tc_bus.ext_slot_base +
  157. tc_bus.ext_slot_size *
  158. tc_bus.num_tcslots - 1;
  159. tc_bus.resource[1].name = tc_bus.name;
  160. tc_bus.resource[1].flags = IORESOURCE_MEM;
  161. if (request_resource(&iomem_resource,
  162. &tc_bus.resource[1]) < 0) {
  163. pr_err("tc: Cannot reserve resource\n");
  164. goto out_err_resource;
  165. }
  166. }
  167. tc_bus_add_devices(&tc_bus);
  168. }
  169. return 0;
  170. out_err_resource:
  171. release_resource(&tc_bus.resource[0]);
  172. out_err_device:
  173. put_device(&tc_bus.dev);
  174. out_err:
  175. return 0;
  176. }
  177. subsys_initcall(tc_init);