zorro.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 <asm/setup.h>
  19. #include <asm/amigahw.h>
  20. #include "zorro.h"
  21. /*
  22. * Zorro Expansion Devices
  23. */
  24. u_int zorro_num_autocon = 0;
  25. struct zorro_dev zorro_autocon[ZORRO_NUM_AUTO];
  26. /*
  27. * Single Zorro bus
  28. */
  29. struct zorro_bus zorro_bus = {\
  30. .resources = {
  31. /* Zorro II regions (on Zorro II/III) */
  32. { .name = "Zorro II exp", .start = 0x00e80000, .end = 0x00efffff },
  33. { .name = "Zorro II mem", .start = 0x00200000, .end = 0x009fffff },
  34. /* Zorro III regions (on Zorro III only) */
  35. { .name = "Zorro III exp", .start = 0xff000000, .end = 0xffffffff },
  36. { .name = "Zorro III cfg", .start = 0x40000000, .end = 0x7fffffff }
  37. },
  38. .name = "Zorro bus"
  39. };
  40. /*
  41. * Find Zorro Devices
  42. */
  43. struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from)
  44. {
  45. struct zorro_dev *z;
  46. if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
  47. return NULL;
  48. for (z = from ? from+1 : &zorro_autocon[0];
  49. z < zorro_autocon+zorro_num_autocon;
  50. z++)
  51. if (id == ZORRO_WILDCARD || id == z->id)
  52. return z;
  53. return NULL;
  54. }
  55. /*
  56. * Bitmask indicating portions of available Zorro II RAM that are unused
  57. * by the system. Every bit represents a 64K chunk, for a maximum of 8MB
  58. * (128 chunks, physical 0x00200000-0x009fffff).
  59. *
  60. * If you want to use (= allocate) portions of this RAM, you should clear
  61. * the corresponding bits.
  62. *
  63. * Possible uses:
  64. * - z2ram device
  65. * - SCSI DMA bounce buffers
  66. *
  67. * FIXME: use the normal resource management
  68. */
  69. DECLARE_BITMAP(zorro_unused_z2ram, 128);
  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(struct zorro_dev *z)
  93. {
  94. int i;
  95. for (i = 0; i < zorro_bus.num_resources; i++)
  96. if (zorro_resource_start(z) >= zorro_bus.resources[i].start &&
  97. zorro_resource_end(z) <= zorro_bus.resources[i].end)
  98. return &zorro_bus.resources[i];
  99. return &iomem_resource;
  100. }
  101. /*
  102. * Initialization
  103. */
  104. static int __init zorro_init(void)
  105. {
  106. struct zorro_dev *z;
  107. unsigned int i;
  108. if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
  109. return 0;
  110. pr_info("Zorro: Probing AutoConfig expansion devices: %d device%s\n",
  111. zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
  112. /* Initialize the Zorro bus */
  113. INIT_LIST_HEAD(&zorro_bus.devices);
  114. strcpy(zorro_bus.dev.bus_id, "zorro");
  115. device_register(&zorro_bus.dev);
  116. /* Request the resources */
  117. zorro_bus.num_resources = AMIGAHW_PRESENT(ZORRO3) ? 4 : 2;
  118. for (i = 0; i < zorro_bus.num_resources; i++)
  119. request_resource(&iomem_resource, &zorro_bus.resources[i]);
  120. /* Register all devices */
  121. for (i = 0; i < zorro_num_autocon; i++) {
  122. z = &zorro_autocon[i];
  123. z->id = (z->rom.er_Manufacturer<<16) | (z->rom.er_Product<<8);
  124. if (z->id == ZORRO_PROD_GVP_EPC_BASE) {
  125. /* GVP quirk */
  126. unsigned long magic = zorro_resource_start(z)+0x8000;
  127. z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK;
  128. }
  129. sprintf(z->name, "Zorro device %08x", z->id);
  130. zorro_name_device(z);
  131. z->resource.name = z->name;
  132. if (request_resource(zorro_find_parent_resource(z), &z->resource))
  133. printk(KERN_ERR "Zorro: Address space collision on device %s "
  134. "[%lx:%lx]\n",
  135. z->name, zorro_resource_start(z), 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");