zorro.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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/byteorder.h>
  20. #include <asm/setup.h>
  21. #include <asm/amigahw.h>
  22. #include "zorro.h"
  23. /*
  24. * Zorro Expansion Devices
  25. */
  26. unsigned int zorro_num_autocon;
  27. struct zorro_dev_init zorro_autocon_init[ZORRO_NUM_AUTO] __initdata;
  28. struct zorro_dev *zorro_autocon;
  29. /*
  30. * Zorro bus
  31. */
  32. struct zorro_bus {
  33. struct device dev;
  34. struct zorro_dev devices[0];
  35. };
  36. /*
  37. * Find Zorro Devices
  38. */
  39. struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from)
  40. {
  41. struct zorro_dev *z;
  42. if (!zorro_num_autocon)
  43. return NULL;
  44. for (z = from ? from+1 : &zorro_autocon[0];
  45. z < zorro_autocon+zorro_num_autocon;
  46. z++)
  47. if (id == ZORRO_WILDCARD || id == z->id)
  48. return z;
  49. return NULL;
  50. }
  51. EXPORT_SYMBOL(zorro_find_device);
  52. /*
  53. * Bitmask indicating portions of available Zorro II RAM that are unused
  54. * by the system. Every bit represents a 64K chunk, for a maximum of 8MB
  55. * (128 chunks, physical 0x00200000-0x009fffff).
  56. *
  57. * If you want to use (= allocate) portions of this RAM, you should clear
  58. * the corresponding bits.
  59. *
  60. * Possible uses:
  61. * - z2ram device
  62. * - SCSI DMA bounce buffers
  63. *
  64. * FIXME: use the normal resource management
  65. */
  66. DECLARE_BITMAP(zorro_unused_z2ram, 128);
  67. EXPORT_SYMBOL(zorro_unused_z2ram);
  68. static void __init mark_region(unsigned long start, unsigned long end,
  69. int flag)
  70. {
  71. if (flag)
  72. start += Z2RAM_CHUNKMASK;
  73. else
  74. end += Z2RAM_CHUNKMASK;
  75. start &= ~Z2RAM_CHUNKMASK;
  76. end &= ~Z2RAM_CHUNKMASK;
  77. if (end <= Z2RAM_START || start >= Z2RAM_END)
  78. return;
  79. start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START;
  80. end = end > Z2RAM_END ? Z2RAM_SIZE : end-Z2RAM_START;
  81. while (start < end) {
  82. u32 chunk = start>>Z2RAM_CHUNKSHIFT;
  83. if (flag)
  84. set_bit(chunk, zorro_unused_z2ram);
  85. else
  86. clear_bit(chunk, zorro_unused_z2ram);
  87. start += Z2RAM_CHUNKSIZE;
  88. }
  89. }
  90. static struct resource __init *zorro_find_parent_resource(
  91. struct platform_device *bridge, struct zorro_dev *z)
  92. {
  93. int i;
  94. for (i = 0; i < bridge->num_resources; i++) {
  95. struct resource *r = &bridge->resource[i];
  96. if (zorro_resource_start(z) >= r->start &&
  97. zorro_resource_end(z) <= r->end)
  98. return r;
  99. }
  100. return &iomem_resource;
  101. }
  102. static int __init amiga_zorro_probe(struct platform_device *pdev)
  103. {
  104. struct zorro_bus *bus;
  105. struct zorro_dev_init *zi;
  106. struct zorro_dev *z;
  107. struct resource *r;
  108. unsigned int i;
  109. int error;
  110. /* Initialize the Zorro bus */
  111. bus = kzalloc(sizeof(*bus) +
  112. zorro_num_autocon * sizeof(bus->devices[0]),
  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)
  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. }
  158. /* ... then register them */
  159. for (i = 0; i < zorro_num_autocon; i++) {
  160. z = &zorro_autocon[i];
  161. error = device_register(&z->dev);
  162. if (error) {
  163. dev_err(&bus->dev, "Error registering device %s\n",
  164. z->name);
  165. put_device(&z->dev);
  166. continue;
  167. }
  168. error = zorro_create_sysfs_dev_files(z);
  169. if (error)
  170. dev_err(&z->dev, "Error creating sysfs files\n");
  171. }
  172. /* Mark all available Zorro II memory */
  173. zorro_for_each_dev(z) {
  174. if (z->rom.er_Type & ERTF_MEMLIST)
  175. mark_region(zorro_resource_start(z),
  176. zorro_resource_end(z)+1, 1);
  177. }
  178. /* Unmark all used Zorro II memory */
  179. for (i = 0; i < m68k_num_memory; i++)
  180. if (m68k_memory[i].addr < 16*1024*1024)
  181. mark_region(m68k_memory[i].addr,
  182. m68k_memory[i].addr+m68k_memory[i].size,
  183. 0);
  184. return 0;
  185. }
  186. static struct platform_driver amiga_zorro_driver = {
  187. .driver = {
  188. .name = "amiga-zorro",
  189. },
  190. };
  191. static int __init amiga_zorro_init(void)
  192. {
  193. return platform_driver_probe(&amiga_zorro_driver, amiga_zorro_probe);
  194. }
  195. module_init(amiga_zorro_init);
  196. MODULE_LICENSE("GPL");