zorro.c 5.1 KB

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