zorro.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * Zorro Bus Services
  3. *
  4. * Copyright (C) 1995-2003 Geert Uytterhoeven
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/types.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/zorro.h>
  15. #include <linux/bitops.h>
  16. #include <linux/string.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/dma-mapping.h>
  19. #include <linux/slab.h>
  20. #include <asm/byteorder.h>
  21. #include <asm/setup.h>
  22. #include <asm/amigahw.h>
  23. #include "zorro.h"
  24. /*
  25. * Zorro Expansion Devices
  26. */
  27. unsigned int zorro_num_autocon;
  28. struct zorro_dev_init zorro_autocon_init[ZORRO_NUM_AUTO] __initdata;
  29. struct zorro_dev *zorro_autocon;
  30. /*
  31. * Zorro bus
  32. */
  33. struct zorro_bus {
  34. struct device dev;
  35. struct zorro_dev devices[0];
  36. };
  37. /*
  38. * Find Zorro Devices
  39. */
  40. struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from)
  41. {
  42. struct zorro_dev *z;
  43. if (!zorro_num_autocon)
  44. return NULL;
  45. for (z = from ? from+1 : &zorro_autocon[0];
  46. z < zorro_autocon+zorro_num_autocon;
  47. z++)
  48. if (id == ZORRO_WILDCARD || id == z->id)
  49. return z;
  50. return NULL;
  51. }
  52. EXPORT_SYMBOL(zorro_find_device);
  53. /*
  54. * Bitmask indicating portions of available Zorro II RAM that are unused
  55. * by the system. Every bit represents a 64K chunk, for a maximum of 8MB
  56. * (128 chunks, physical 0x00200000-0x009fffff).
  57. *
  58. * If you want to use (= allocate) portions of this RAM, you should clear
  59. * the corresponding bits.
  60. *
  61. * Possible uses:
  62. * - z2ram device
  63. * - SCSI DMA bounce buffers
  64. *
  65. * FIXME: use the normal resource management
  66. */
  67. DECLARE_BITMAP(zorro_unused_z2ram, 128);
  68. EXPORT_SYMBOL(zorro_unused_z2ram);
  69. static void __init mark_region(unsigned long start, unsigned long end,
  70. int flag)
  71. {
  72. if (flag)
  73. start += Z2RAM_CHUNKMASK;
  74. else
  75. end += Z2RAM_CHUNKMASK;
  76. start &= ~Z2RAM_CHUNKMASK;
  77. end &= ~Z2RAM_CHUNKMASK;
  78. if (end <= Z2RAM_START || start >= Z2RAM_END)
  79. return;
  80. start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START;
  81. end = end > Z2RAM_END ? Z2RAM_SIZE : end-Z2RAM_START;
  82. while (start < end) {
  83. u32 chunk = start>>Z2RAM_CHUNKSHIFT;
  84. if (flag)
  85. set_bit(chunk, zorro_unused_z2ram);
  86. else
  87. clear_bit(chunk, zorro_unused_z2ram);
  88. start += Z2RAM_CHUNKSIZE;
  89. }
  90. }
  91. static struct resource __init *zorro_find_parent_resource(
  92. struct platform_device *bridge, struct zorro_dev *z)
  93. {
  94. int i;
  95. for (i = 0; i < bridge->num_resources; i++) {
  96. struct resource *r = &bridge->resource[i];
  97. if (zorro_resource_start(z) >= r->start &&
  98. zorro_resource_end(z) <= r->end)
  99. return r;
  100. }
  101. return &iomem_resource;
  102. }
  103. static int __init amiga_zorro_probe(struct platform_device *pdev)
  104. {
  105. struct zorro_bus *bus;
  106. struct zorro_dev_init *zi;
  107. struct zorro_dev *z;
  108. struct resource *r;
  109. unsigned int i;
  110. int error;
  111. /* Initialize the Zorro bus */
  112. bus = kzalloc(sizeof(*bus) +
  113. zorro_num_autocon * sizeof(bus->devices[0]),
  114. GFP_KERNEL);
  115. if (!bus)
  116. return -ENOMEM;
  117. zorro_autocon = bus->devices;
  118. bus->dev.parent = &pdev->dev;
  119. dev_set_name(&bus->dev, zorro_bus_type.name);
  120. error = device_register(&bus->dev);
  121. if (error) {
  122. pr_err("Zorro: Error registering zorro_bus\n");
  123. put_device(&bus->dev);
  124. kfree(bus);
  125. return error;
  126. }
  127. platform_set_drvdata(pdev, bus);
  128. pr_info("Zorro: Probing AutoConfig expansion devices: %u device%s\n",
  129. zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
  130. /* First identify all devices ... */
  131. for (i = 0; i < zorro_num_autocon; i++) {
  132. zi = &zorro_autocon_init[i];
  133. z = &zorro_autocon[i];
  134. z->rom = zi->rom;
  135. z->id = (be16_to_cpu(z->rom.er_Manufacturer) << 16) |
  136. (z->rom.er_Product << 8);
  137. if (z->id == ZORRO_PROD_GVP_EPC_BASE) {
  138. /* GVP quirk */
  139. unsigned long magic = zi->boardaddr + 0x8000;
  140. z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK;
  141. }
  142. z->slotaddr = zi->slotaddr;
  143. z->slotsize = zi->slotsize;
  144. sprintf(z->name, "Zorro device %08x", z->id);
  145. zorro_name_device(z);
  146. z->resource.start = zi->boardaddr;
  147. z->resource.end = zi->boardaddr + zi->boardsize - 1;
  148. z->resource.name = z->name;
  149. r = zorro_find_parent_resource(pdev, z);
  150. error = request_resource(r, &z->resource);
  151. if (error)
  152. dev_err(&bus->dev,
  153. "Address space collision on device %s %pR\n",
  154. z->name, &z->resource);
  155. z->dev.parent = &bus->dev;
  156. z->dev.bus = &zorro_bus_type;
  157. z->dev.id = i;
  158. switch (z->rom.er_Type & ERT_TYPEMASK) {
  159. case ERT_ZORROIII:
  160. z->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  161. break;
  162. case ERT_ZORROII:
  163. default:
  164. z->dev.coherent_dma_mask = DMA_BIT_MASK(24);
  165. break;
  166. }
  167. z->dev.dma_mask = &z->dev.coherent_dma_mask;
  168. }
  169. /* ... then register them */
  170. for (i = 0; i < zorro_num_autocon; i++) {
  171. z = &zorro_autocon[i];
  172. error = device_register(&z->dev);
  173. if (error) {
  174. dev_err(&bus->dev, "Error registering device %s\n",
  175. z->name);
  176. put_device(&z->dev);
  177. continue;
  178. }
  179. error = zorro_create_sysfs_dev_files(z);
  180. if (error)
  181. dev_err(&z->dev, "Error creating sysfs files\n");
  182. }
  183. /* Mark all available Zorro II memory */
  184. zorro_for_each_dev(z) {
  185. if (z->rom.er_Type & ERTF_MEMLIST)
  186. mark_region(zorro_resource_start(z),
  187. zorro_resource_end(z)+1, 1);
  188. }
  189. /* Unmark all used Zorro II memory */
  190. for (i = 0; i < m68k_num_memory; i++)
  191. if (m68k_memory[i].addr < 16*1024*1024)
  192. mark_region(m68k_memory[i].addr,
  193. m68k_memory[i].addr+m68k_memory[i].size,
  194. 0);
  195. return 0;
  196. }
  197. static struct platform_driver amiga_zorro_driver = {
  198. .driver = {
  199. .name = "amiga-zorro",
  200. },
  201. };
  202. static int __init amiga_zorro_init(void)
  203. {
  204. return platform_driver_probe(&amiga_zorro_driver, amiga_zorro_probe);
  205. }
  206. module_init(amiga_zorro_init);
  207. MODULE_LICENSE("GPL");