zorro.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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[];
  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(struct_size(bus, devices, zorro_num_autocon),
  113. GFP_KERNEL);
  114. if (!bus)
  115. return -ENOMEM;
  116. zorro_autocon = bus->devices;
  117. bus->dev.parent = &pdev->dev;
  118. dev_set_name(&bus->dev, zorro_bus_type.name);
  119. error = device_register(&bus->dev);
  120. if (error) {
  121. pr_err("Zorro: Error registering zorro_bus\n");
  122. put_device(&bus->dev);
  123. kfree(bus);
  124. return error;
  125. }
  126. platform_set_drvdata(pdev, bus);
  127. pr_info("Zorro: Probing AutoConfig expansion devices: %u device%s\n",
  128. zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
  129. /* First identify all devices ... */
  130. for (i = 0; i < zorro_num_autocon; i++) {
  131. zi = &zorro_autocon_init[i];
  132. z = &zorro_autocon[i];
  133. z->rom = zi->rom;
  134. z->id = (be16_to_cpu(z->rom.er_Manufacturer) << 16) |
  135. (z->rom.er_Product << 8);
  136. if (z->id == ZORRO_PROD_GVP_EPC_BASE) {
  137. /* GVP quirk */
  138. unsigned long magic = zi->boardaddr + 0x8000;
  139. z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK;
  140. }
  141. z->slotaddr = zi->slotaddr;
  142. z->slotsize = zi->slotsize;
  143. sprintf(z->name, "Zorro device %08x", z->id);
  144. zorro_name_device(z);
  145. z->resource.start = zi->boardaddr;
  146. z->resource.end = zi->boardaddr + zi->boardsize - 1;
  147. z->resource.name = z->name;
  148. r = zorro_find_parent_resource(pdev, z);
  149. error = request_resource(r, &z->resource);
  150. if (error && !(z->rom.er_Type & ERTF_MEMLIST))
  151. dev_err(&bus->dev,
  152. "Address space collision on device %s %pR\n",
  153. z->name, &z->resource);
  154. z->dev.parent = &bus->dev;
  155. z->dev.bus = &zorro_bus_type;
  156. z->dev.id = i;
  157. switch (z->rom.er_Type & ERT_TYPEMASK) {
  158. case ERT_ZORROIII:
  159. z->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  160. break;
  161. case ERT_ZORROII:
  162. default:
  163. z->dev.coherent_dma_mask = DMA_BIT_MASK(24);
  164. break;
  165. }
  166. z->dev.dma_mask = &z->dev.coherent_dma_mask;
  167. }
  168. /* ... then register them */
  169. for (i = 0; i < zorro_num_autocon; i++) {
  170. z = &zorro_autocon[i];
  171. error = device_register(&z->dev);
  172. if (error) {
  173. dev_err(&bus->dev, "Error registering device %s\n",
  174. z->name);
  175. put_device(&z->dev);
  176. continue;
  177. }
  178. }
  179. /* Mark all available Zorro II memory */
  180. zorro_for_each_dev(z) {
  181. if (z->rom.er_Type & ERTF_MEMLIST)
  182. mark_region(zorro_resource_start(z),
  183. zorro_resource_end(z)+1, 1);
  184. }
  185. /* Unmark all used Zorro II memory */
  186. for (i = 0; i < m68k_num_memory; i++)
  187. if (m68k_memory[i].addr < 16*1024*1024)
  188. mark_region(m68k_memory[i].addr,
  189. m68k_memory[i].addr+m68k_memory[i].size,
  190. 0);
  191. return 0;
  192. }
  193. static struct platform_driver amiga_zorro_driver = {
  194. .driver = {
  195. .name = "amiga-zorro",
  196. },
  197. };
  198. static int __init amiga_zorro_init(void)
  199. {
  200. return platform_driver_probe(&amiga_zorro_driver, amiga_zorro_probe);
  201. }
  202. module_init(amiga_zorro_init);
  203. MODULE_LICENSE("GPL");