tc.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. printk(KERN_ERR "tc%x: unable to allocate tc_dev\n",
  77. slot);
  78. goto out_err;
  79. }
  80. dev_set_name(&tdev->dev, "tc%x", slot);
  81. tdev->bus = tbus;
  82. tdev->dev.parent = &tbus->dev;
  83. tdev->dev.bus = &tc_bus_type;
  84. tdev->slot = slot;
  85. for (i = 0; i < 8; i++) {
  86. tdev->firmware[i] =
  87. readb(module + offset + TC_FIRM_VER + 4 * i);
  88. tdev->vendor[i] =
  89. readb(module + offset + TC_VENDOR + 4 * i);
  90. tdev->name[i] =
  91. readb(module + offset + TC_MODULE + 4 * i);
  92. }
  93. tdev->firmware[8] = 0;
  94. tdev->vendor[8] = 0;
  95. tdev->name[8] = 0;
  96. pr_info("%s: %s %s %s\n", dev_name(&tdev->dev), tdev->vendor,
  97. tdev->name, tdev->firmware);
  98. devsize = readb(module + offset + TC_SLOT_SIZE);
  99. devsize <<= 22;
  100. if (devsize <= slotsize) {
  101. tdev->resource.start = slotaddr;
  102. tdev->resource.end = slotaddr + devsize - 1;
  103. } else if (devsize <= extslotsize) {
  104. tdev->resource.start = extslotaddr;
  105. tdev->resource.end = extslotaddr + devsize - 1;
  106. } else {
  107. printk(KERN_ERR "%s: Cannot provide slot space "
  108. "(%dMiB required, up to %dMiB supported)\n",
  109. dev_name(&tdev->dev), devsize >> 20,
  110. max(slotsize, extslotsize) >> 20);
  111. kfree(tdev);
  112. goto out_err;
  113. }
  114. tdev->resource.name = tdev->name;
  115. tdev->resource.flags = IORESOURCE_MEM;
  116. tc_device_get_irq(tdev);
  117. if (device_register(&tdev->dev)) {
  118. put_device(&tdev->dev);
  119. goto out_err;
  120. }
  121. list_add_tail(&tdev->node, &tbus->devices);
  122. out_err:
  123. iounmap(module);
  124. }
  125. }
  126. /*
  127. * The main entry.
  128. */
  129. static int __init tc_init(void)
  130. {
  131. /* Initialize the TURBOchannel bus */
  132. if (tc_bus_get_info(&tc_bus))
  133. return 0;
  134. INIT_LIST_HEAD(&tc_bus.devices);
  135. dev_set_name(&tc_bus.dev, "tc");
  136. if (device_register(&tc_bus.dev)) {
  137. put_device(&tc_bus.dev);
  138. return 0;
  139. }
  140. if (tc_bus.info.slot_size) {
  141. unsigned int tc_clock = tc_get_speed(&tc_bus) / 100000;
  142. pr_info("tc: TURBOchannel rev. %d at %d.%d MHz "
  143. "(with%s parity)\n", tc_bus.info.revision,
  144. tc_clock / 10, tc_clock % 10,
  145. tc_bus.info.parity ? "" : "out");
  146. tc_bus.resource[0].start = tc_bus.slot_base;
  147. tc_bus.resource[0].end = tc_bus.slot_base +
  148. (tc_bus.info.slot_size << 20) *
  149. tc_bus.num_tcslots - 1;
  150. tc_bus.resource[0].name = tc_bus.name;
  151. tc_bus.resource[0].flags = IORESOURCE_MEM;
  152. if (request_resource(&iomem_resource,
  153. &tc_bus.resource[0]) < 0) {
  154. printk(KERN_ERR "tc: Cannot reserve resource\n");
  155. return 0;
  156. }
  157. if (tc_bus.ext_slot_size) {
  158. tc_bus.resource[1].start = tc_bus.ext_slot_base;
  159. tc_bus.resource[1].end = tc_bus.ext_slot_base +
  160. tc_bus.ext_slot_size *
  161. tc_bus.num_tcslots - 1;
  162. tc_bus.resource[1].name = tc_bus.name;
  163. tc_bus.resource[1].flags = IORESOURCE_MEM;
  164. if (request_resource(&iomem_resource,
  165. &tc_bus.resource[1]) < 0) {
  166. printk(KERN_ERR
  167. "tc: Cannot reserve resource\n");
  168. release_resource(&tc_bus.resource[0]);
  169. return 0;
  170. }
  171. }
  172. tc_bus_add_devices(&tc_bus);
  173. }
  174. return 0;
  175. }
  176. subsys_initcall(tc_init);