zorro.c 5.4 KB

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