zorro.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * $Id: zorro.c,v 1.1.2.1 1998/06/07 23:21:02 geert Exp $
  3. *
  4. * Zorro Bus Services
  5. *
  6. * Copyright (C) 1995-2003 Geert Uytterhoeven
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file COPYING in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/zorro.h>
  17. #include <linux/bitops.h>
  18. #include <linux/string.h>
  19. #include <asm/setup.h>
  20. #include <asm/amigahw.h>
  21. #include "zorro.h"
  22. /*
  23. * Zorro Expansion Devices
  24. */
  25. u_int zorro_num_autocon = 0;
  26. struct zorro_dev zorro_autocon[ZORRO_NUM_AUTO];
  27. /*
  28. * Single Zorro bus
  29. */
  30. struct zorro_bus zorro_bus = {\
  31. .resources = {
  32. /* Zorro II regions (on Zorro II/III) */
  33. { .name = "Zorro II exp", .start = 0x00e80000, .end = 0x00efffff },
  34. { .name = "Zorro II mem", .start = 0x00200000, .end = 0x009fffff },
  35. /* Zorro III regions (on Zorro III only) */
  36. { .name = "Zorro III exp", .start = 0xff000000, .end = 0xffffffff },
  37. { .name = "Zorro III cfg", .start = 0x40000000, .end = 0x7fffffff }
  38. },
  39. .name = "Zorro bus"
  40. };
  41. /*
  42. * Find Zorro Devices
  43. */
  44. struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from)
  45. {
  46. struct zorro_dev *z;
  47. if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
  48. return NULL;
  49. for (z = from ? from+1 : &zorro_autocon[0];
  50. z < zorro_autocon+zorro_num_autocon;
  51. z++)
  52. if (id == ZORRO_WILDCARD || id == z->id)
  53. return z;
  54. return NULL;
  55. }
  56. /*
  57. * Bitmask indicating portions of available Zorro II RAM that are unused
  58. * by the system. Every bit represents a 64K chunk, for a maximum of 8MB
  59. * (128 chunks, physical 0x00200000-0x009fffff).
  60. *
  61. * If you want to use (= allocate) portions of this RAM, you should clear
  62. * the corresponding bits.
  63. *
  64. * Possible uses:
  65. * - z2ram device
  66. * - SCSI DMA bounce buffers
  67. *
  68. * FIXME: use the normal resource management
  69. */
  70. DECLARE_BITMAP(zorro_unused_z2ram, 128);
  71. static void __init mark_region(unsigned long start, unsigned long end,
  72. int flag)
  73. {
  74. if (flag)
  75. start += Z2RAM_CHUNKMASK;
  76. else
  77. end += Z2RAM_CHUNKMASK;
  78. start &= ~Z2RAM_CHUNKMASK;
  79. end &= ~Z2RAM_CHUNKMASK;
  80. if (end <= Z2RAM_START || start >= Z2RAM_END)
  81. return;
  82. start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START;
  83. end = end > Z2RAM_END ? Z2RAM_SIZE : end-Z2RAM_START;
  84. while (start < end) {
  85. u32 chunk = start>>Z2RAM_CHUNKSHIFT;
  86. if (flag)
  87. set_bit(chunk, zorro_unused_z2ram);
  88. else
  89. clear_bit(chunk, zorro_unused_z2ram);
  90. start += Z2RAM_CHUNKSIZE;
  91. }
  92. }
  93. static struct resource __init *zorro_find_parent_resource(struct zorro_dev *z)
  94. {
  95. int i;
  96. for (i = 0; i < zorro_bus.num_resources; i++)
  97. if (zorro_resource_start(z) >= zorro_bus.resources[i].start &&
  98. zorro_resource_end(z) <= zorro_bus.resources[i].end)
  99. return &zorro_bus.resources[i];
  100. return &iomem_resource;
  101. }
  102. /*
  103. * Initialization
  104. */
  105. static int __init zorro_init(void)
  106. {
  107. struct zorro_dev *z;
  108. unsigned int i;
  109. if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
  110. return 0;
  111. pr_info("Zorro: Probing AutoConfig expansion devices: %d device%s\n",
  112. zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
  113. /* Initialize the Zorro bus */
  114. INIT_LIST_HEAD(&zorro_bus.devices);
  115. strcpy(zorro_bus.dev.bus_id, "zorro");
  116. device_register(&zorro_bus.dev);
  117. /* Request the resources */
  118. zorro_bus.num_resources = AMIGAHW_PRESENT(ZORRO3) ? 4 : 2;
  119. for (i = 0; i < zorro_bus.num_resources; i++)
  120. request_resource(&iomem_resource, &zorro_bus.resources[i]);
  121. /* Register all devices */
  122. for (i = 0; i < zorro_num_autocon; i++) {
  123. z = &zorro_autocon[i];
  124. z->id = (z->rom.er_Manufacturer<<16) | (z->rom.er_Product<<8);
  125. if (z->id == ZORRO_PROD_GVP_EPC_BASE) {
  126. /* GVP quirk */
  127. unsigned long magic = zorro_resource_start(z)+0x8000;
  128. z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK;
  129. }
  130. sprintf(z->name, "Zorro device %08x", z->id);
  131. zorro_name_device(z);
  132. z->resource.name = z->name;
  133. if (request_resource(zorro_find_parent_resource(z), &z->resource))
  134. printk(KERN_ERR "Zorro: Address space collision on device %s "
  135. "[%lx:%lx]\n",
  136. z->name, zorro_resource_start(z), zorro_resource_end(z));
  137. sprintf(z->dev.bus_id, "%02x", i);
  138. z->dev.parent = &zorro_bus.dev;
  139. z->dev.bus = &zorro_bus_type;
  140. device_register(&z->dev);
  141. zorro_create_sysfs_dev_files(z);
  142. }
  143. /* Mark all available Zorro II memory */
  144. zorro_for_each_dev(z) {
  145. if (z->rom.er_Type & ERTF_MEMLIST)
  146. mark_region(zorro_resource_start(z), zorro_resource_end(z)+1, 1);
  147. }
  148. /* Unmark all used Zorro II memory */
  149. for (i = 0; i < m68k_num_memory; i++)
  150. if (m68k_memory[i].addr < 16*1024*1024)
  151. mark_region(m68k_memory[i].addr,
  152. m68k_memory[i].addr+m68k_memory[i].size, 0);
  153. return 0;
  154. }
  155. subsys_initcall(zorro_init);
  156. EXPORT_SYMBOL(zorro_find_device);
  157. EXPORT_SYMBOL(zorro_unused_z2ram);
  158. MODULE_LICENSE("GPL");