zorro.c 5.1 KB

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