zorro.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 <asm/setup.h>
  18. #include <asm/amigahw.h>
  19. #include "zorro.h"
  20. /*
  21. * Zorro Expansion Devices
  22. */
  23. u_int zorro_num_autocon = 0;
  24. struct zorro_dev zorro_autocon[ZORRO_NUM_AUTO];
  25. /*
  26. * Single Zorro bus
  27. */
  28. struct zorro_bus zorro_bus = {\
  29. .resources = {
  30. /* Zorro II regions (on Zorro II/III) */
  31. { .name = "Zorro II exp", .start = 0x00e80000, .end = 0x00efffff },
  32. { .name = "Zorro II mem", .start = 0x00200000, .end = 0x009fffff },
  33. /* Zorro III regions (on Zorro III only) */
  34. { .name = "Zorro III exp", .start = 0xff000000, .end = 0xffffffff },
  35. { .name = "Zorro III cfg", .start = 0x40000000, .end = 0x7fffffff }
  36. },
  37. .name = "Zorro bus"
  38. };
  39. /*
  40. * Find Zorro Devices
  41. */
  42. struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from)
  43. {
  44. struct zorro_dev *z;
  45. if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
  46. return NULL;
  47. for (z = from ? from+1 : &zorro_autocon[0];
  48. z < zorro_autocon+zorro_num_autocon;
  49. z++)
  50. if (id == ZORRO_WILDCARD || id == z->id)
  51. return z;
  52. return NULL;
  53. }
  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. static void __init mark_region(unsigned long start, unsigned long end,
  70. int flag)
  71. {
  72. if (flag)
  73. start += Z2RAM_CHUNKMASK;
  74. else
  75. end += Z2RAM_CHUNKMASK;
  76. start &= ~Z2RAM_CHUNKMASK;
  77. end &= ~Z2RAM_CHUNKMASK;
  78. if (end <= Z2RAM_START || start >= Z2RAM_END)
  79. return;
  80. start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START;
  81. end = end > Z2RAM_END ? Z2RAM_SIZE : end-Z2RAM_START;
  82. while (start < end) {
  83. u32 chunk = start>>Z2RAM_CHUNKSHIFT;
  84. if (flag)
  85. set_bit(chunk, zorro_unused_z2ram);
  86. else
  87. clear_bit(chunk, zorro_unused_z2ram);
  88. start += Z2RAM_CHUNKSIZE;
  89. }
  90. }
  91. static struct resource __init *zorro_find_parent_resource(struct zorro_dev *z)
  92. {
  93. int i;
  94. for (i = 0; i < zorro_bus.num_resources; i++)
  95. if (zorro_resource_start(z) >= zorro_bus.resources[i].start &&
  96. zorro_resource_end(z) <= zorro_bus.resources[i].end)
  97. return &zorro_bus.resources[i];
  98. return &iomem_resource;
  99. }
  100. /*
  101. * Initialization
  102. */
  103. static int __init zorro_init(void)
  104. {
  105. struct zorro_dev *z;
  106. unsigned int i;
  107. if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
  108. return 0;
  109. pr_info("Zorro: Probing AutoConfig expansion devices: %d device%s\n",
  110. zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
  111. /* Initialize the Zorro bus */
  112. INIT_LIST_HEAD(&zorro_bus.devices);
  113. strcpy(zorro_bus.dev.bus_id, "zorro");
  114. device_register(&zorro_bus.dev);
  115. /* Request the resources */
  116. zorro_bus.num_resources = AMIGAHW_PRESENT(ZORRO3) ? 4 : 2;
  117. for (i = 0; i < zorro_bus.num_resources; i++)
  118. request_resource(&iomem_resource, &zorro_bus.resources[i]);
  119. /* Register all devices */
  120. for (i = 0; i < zorro_num_autocon; i++) {
  121. z = &zorro_autocon[i];
  122. z->id = (z->rom.er_Manufacturer<<16) | (z->rom.er_Product<<8);
  123. if (z->id == ZORRO_PROD_GVP_EPC_BASE) {
  124. /* GVP quirk */
  125. unsigned long magic = zorro_resource_start(z)+0x8000;
  126. z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK;
  127. }
  128. sprintf(z->name, "Zorro device %08x", z->id);
  129. zorro_name_device(z);
  130. z->resource.name = z->name;
  131. if (request_resource(zorro_find_parent_resource(z), &z->resource))
  132. printk(KERN_ERR "Zorro: Address space collision on device %s "
  133. "[%lx:%lx]\n",
  134. z->name, (unsigned long)zorro_resource_start(z),
  135. (unsigned long)zorro_resource_end(z));
  136. sprintf(z->dev.bus_id, "%02x", i);
  137. z->dev.parent = &zorro_bus.dev;
  138. z->dev.bus = &zorro_bus_type;
  139. device_register(&z->dev);
  140. zorro_create_sysfs_dev_files(z);
  141. }
  142. /* Mark all available Zorro II memory */
  143. zorro_for_each_dev(z) {
  144. if (z->rom.er_Type & ERTF_MEMLIST)
  145. mark_region(zorro_resource_start(z), zorro_resource_end(z)+1, 1);
  146. }
  147. /* Unmark all used Zorro II memory */
  148. for (i = 0; i < m68k_num_memory; i++)
  149. if (m68k_memory[i].addr < 16*1024*1024)
  150. mark_region(m68k_memory[i].addr,
  151. m68k_memory[i].addr+m68k_memory[i].size, 0);
  152. return 0;
  153. }
  154. subsys_initcall(zorro_init);
  155. EXPORT_SYMBOL(zorro_find_device);
  156. EXPORT_SYMBOL(zorro_unused_z2ram);
  157. MODULE_LICENSE("GPL");