zorro.c 5.6 KB

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