tc.c 5.5 KB

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