zorro.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. * linux/zorro.h -- Amiga AutoConfig (Zorro) Bus Definitions
  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. #ifndef _LINUX_ZORRO_H
  11. #define _LINUX_ZORRO_H
  12. #ifndef __ASSEMBLY__
  13. #include <linux/device.h>
  14. /*
  15. * Each Zorro board has a 32-bit ID of the form
  16. *
  17. * mmmmmmmmmmmmmmmmppppppppeeeeeeee
  18. *
  19. * with
  20. *
  21. * mmmmmmmmmmmmmmmm 16-bit Manufacturer ID (assigned by CBM (sigh))
  22. * pppppppp 8-bit Product ID (assigned by manufacturer)
  23. * eeeeeeee 8-bit Extended Product ID (currently only used
  24. * for some GVP boards)
  25. */
  26. #define ZORRO_MANUF(id) ((id) >> 16)
  27. #define ZORRO_PROD(id) (((id) >> 8) & 0xff)
  28. #define ZORRO_EPC(id) ((id) & 0xff)
  29. #define ZORRO_ID(manuf, prod, epc) \
  30. ((ZORRO_MANUF_##manuf << 16) | ((prod) << 8) | (epc))
  31. typedef __u32 zorro_id;
  32. #define ZORRO_WILDCARD (0xffffffff) /* not official */
  33. /* Include the ID list */
  34. #include <linux/zorro_ids.h>
  35. /*
  36. * GVP identifies most of its products through the 'extended product code'
  37. * (epc). The epc has to be ANDed with the GVP_PRODMASK before the
  38. * identification.
  39. */
  40. #define GVP_PRODMASK (0xf8)
  41. #define GVP_SCSICLKMASK (0x01)
  42. enum GVP_flags {
  43. GVP_IO = 0x01,
  44. GVP_ACCEL = 0x02,
  45. GVP_SCSI = 0x04,
  46. GVP_24BITDMA = 0x08,
  47. GVP_25BITDMA = 0x10,
  48. GVP_NOBANK = 0x20,
  49. GVP_14MHZ = 0x40,
  50. };
  51. struct Node {
  52. struct Node *ln_Succ; /* Pointer to next (successor) */
  53. struct Node *ln_Pred; /* Pointer to previous (predecessor) */
  54. __u8 ln_Type;
  55. __s8 ln_Pri; /* Priority, for sorting */
  56. __s8 *ln_Name; /* ID string, null terminated */
  57. } __attribute__ ((packed));
  58. struct ExpansionRom {
  59. /* -First 16 bytes of the expansion ROM */
  60. __u8 er_Type; /* Board type, size and flags */
  61. __u8 er_Product; /* Product number, assigned by manufacturer */
  62. __u8 er_Flags; /* Flags */
  63. __u8 er_Reserved03; /* Must be zero ($ff inverted) */
  64. __u16 er_Manufacturer; /* Unique ID, ASSIGNED BY COMMODORE-AMIGA! */
  65. __u32 er_SerialNumber; /* Available for use by manufacturer */
  66. __u16 er_InitDiagVec; /* Offset to optional "DiagArea" structure */
  67. __u8 er_Reserved0c;
  68. __u8 er_Reserved0d;
  69. __u8 er_Reserved0e;
  70. __u8 er_Reserved0f;
  71. } __attribute__ ((packed));
  72. /* er_Type board type bits */
  73. #define ERT_TYPEMASK 0xc0
  74. #define ERT_ZORROII 0xc0
  75. #define ERT_ZORROIII 0x80
  76. /* other bits defined in er_Type */
  77. #define ERTB_MEMLIST 5 /* Link RAM into free memory list */
  78. #define ERTF_MEMLIST (1<<5)
  79. struct ConfigDev {
  80. struct Node cd_Node;
  81. __u8 cd_Flags; /* (read/write) */
  82. __u8 cd_Pad; /* reserved */
  83. struct ExpansionRom cd_Rom; /* copy of board's expansion ROM */
  84. void *cd_BoardAddr; /* where in memory the board was placed */
  85. __u32 cd_BoardSize; /* size of board in bytes */
  86. __u16 cd_SlotAddr; /* which slot number (PRIVATE) */
  87. __u16 cd_SlotSize; /* number of slots (PRIVATE) */
  88. void *cd_Driver; /* pointer to node of driver */
  89. struct ConfigDev *cd_NextCD; /* linked list of drivers to config */
  90. __u32 cd_Unused[4]; /* for whatever the driver wants */
  91. } __attribute__ ((packed));
  92. #else /* __ASSEMBLY__ */
  93. LN_Succ = 0
  94. LN_Pred = LN_Succ+4
  95. LN_Type = LN_Pred+4
  96. LN_Pri = LN_Type+1
  97. LN_Name = LN_Pri+1
  98. LN_sizeof = LN_Name+4
  99. ER_Type = 0
  100. ER_Product = ER_Type+1
  101. ER_Flags = ER_Product+1
  102. ER_Reserved03 = ER_Flags+1
  103. ER_Manufacturer = ER_Reserved03+1
  104. ER_SerialNumber = ER_Manufacturer+2
  105. ER_InitDiagVec = ER_SerialNumber+4
  106. ER_Reserved0c = ER_InitDiagVec+2
  107. ER_Reserved0d = ER_Reserved0c+1
  108. ER_Reserved0e = ER_Reserved0d+1
  109. ER_Reserved0f = ER_Reserved0e+1
  110. ER_sizeof = ER_Reserved0f+1
  111. CD_Node = 0
  112. CD_Flags = CD_Node+LN_sizeof
  113. CD_Pad = CD_Flags+1
  114. CD_Rom = CD_Pad+1
  115. CD_BoardAddr = CD_Rom+ER_sizeof
  116. CD_BoardSize = CD_BoardAddr+4
  117. CD_SlotAddr = CD_BoardSize+4
  118. CD_SlotSize = CD_SlotAddr+2
  119. CD_Driver = CD_SlotSize+2
  120. CD_NextCD = CD_Driver+4
  121. CD_Unused = CD_NextCD+4
  122. CD_sizeof = CD_Unused+(4*4)
  123. #endif /* __ASSEMBLY__ */
  124. #ifndef __ASSEMBLY__
  125. #define ZORRO_NUM_AUTO 16
  126. #ifdef __KERNEL__
  127. #include <linux/init.h>
  128. #include <linux/ioport.h>
  129. #include <asm/zorro.h>
  130. /*
  131. * Zorro devices
  132. */
  133. struct zorro_dev {
  134. struct ExpansionRom rom;
  135. zorro_id id;
  136. struct zorro_driver *driver; /* which driver has allocated this device */
  137. struct device dev; /* Generic device interface */
  138. u16 slotaddr;
  139. u16 slotsize;
  140. char name[64];
  141. struct resource resource;
  142. };
  143. #define to_zorro_dev(n) container_of(n, struct zorro_dev, dev)
  144. /*
  145. * Zorro bus
  146. */
  147. struct zorro_bus {
  148. struct list_head devices; /* list of devices on this bus */
  149. unsigned int num_resources; /* number of resources */
  150. struct resource resources[4]; /* address space routed to this bus */
  151. struct device dev;
  152. char name[10];
  153. };
  154. extern struct zorro_bus zorro_bus; /* single Zorro bus */
  155. extern struct bus_type zorro_bus_type;
  156. /*
  157. * Zorro device IDs
  158. */
  159. struct zorro_device_id {
  160. zorro_id id; /* Device ID or ZORRO_WILDCARD */
  161. unsigned long driver_data; /* Data private to the driver */
  162. };
  163. /*
  164. * Zorro device drivers
  165. */
  166. struct zorro_driver {
  167. struct list_head node;
  168. char *name;
  169. const struct zorro_device_id *id_table; /* NULL if wants all devices */
  170. int (*probe)(struct zorro_dev *z, const struct zorro_device_id *id); /* New device inserted */
  171. void (*remove)(struct zorro_dev *z); /* Device removed (NULL if not a hot-plug capable driver) */
  172. struct device_driver driver;
  173. };
  174. #define to_zorro_driver(drv) container_of(drv, struct zorro_driver, driver)
  175. #define zorro_for_each_dev(dev) \
  176. for (dev = &zorro_autocon[0]; dev < zorro_autocon+zorro_num_autocon; dev++)
  177. /* New-style probing */
  178. extern int zorro_register_driver(struct zorro_driver *);
  179. extern void zorro_unregister_driver(struct zorro_driver *);
  180. extern const struct zorro_device_id *zorro_match_device(const struct zorro_device_id *ids, const struct zorro_dev *z);
  181. static inline struct zorro_driver *zorro_dev_driver(const struct zorro_dev *z)
  182. {
  183. return z->driver;
  184. }
  185. extern unsigned int zorro_num_autocon; /* # of autoconfig devices found */
  186. extern struct zorro_dev zorro_autocon[ZORRO_NUM_AUTO];
  187. /*
  188. * Zorro Functions
  189. */
  190. extern struct zorro_dev *zorro_find_device(zorro_id id,
  191. struct zorro_dev *from);
  192. #define zorro_resource_start(z) ((z)->resource.start)
  193. #define zorro_resource_end(z) ((z)->resource.end)
  194. #define zorro_resource_len(z) ((z)->resource.end-(z)->resource.start+1)
  195. #define zorro_resource_flags(z) ((z)->resource.flags)
  196. #define zorro_request_device(z, name) \
  197. request_mem_region(zorro_resource_start(z), zorro_resource_len(z), name)
  198. #define zorro_release_device(z) \
  199. release_mem_region(zorro_resource_start(z), zorro_resource_len(z))
  200. /* Similar to the helpers above, these manipulate per-zorro_dev
  201. * driver-specific data. They are really just a wrapper around
  202. * the generic device structure functions of these calls.
  203. */
  204. static inline void *zorro_get_drvdata (struct zorro_dev *z)
  205. {
  206. return dev_get_drvdata(&z->dev);
  207. }
  208. static inline void zorro_set_drvdata (struct zorro_dev *z, void *data)
  209. {
  210. dev_set_drvdata(&z->dev, data);
  211. }
  212. /*
  213. * A helper function which helps ensure correct zorro_driver
  214. * setup and cleanup for commonly-encountered hotplug/modular cases
  215. *
  216. * This MUST stay in a header, as it checks for -DMODULE
  217. */
  218. static inline int zorro_module_init(struct zorro_driver *drv)
  219. {
  220. int rc = zorro_register_driver(drv);
  221. if (rc > 0)
  222. return 0;
  223. /* iff CONFIG_HOTPLUG and built into kernel, we should
  224. * leave the driver around for future hotplug events.
  225. * For the module case, a hotplug daemon of some sort
  226. * should load a module in response to an insert event. */
  227. #if defined(CONFIG_HOTPLUG) && !defined(MODULE)
  228. if (rc == 0)
  229. return 0;
  230. #else
  231. if (rc == 0)
  232. rc = -ENODEV;
  233. #endif
  234. /* if we get here, we need to clean up Zorro driver instance
  235. * and return some sort of error */
  236. zorro_unregister_driver(drv);
  237. return rc;
  238. }
  239. /*
  240. * Bitmask indicating portions of available Zorro II RAM that are unused
  241. * by the system. Every bit represents a 64K chunk, for a maximum of 8MB
  242. * (128 chunks, physical 0x00200000-0x009fffff).
  243. *
  244. * If you want to use (= allocate) portions of this RAM, you should clear
  245. * the corresponding bits.
  246. */
  247. extern DECLARE_BITMAP(zorro_unused_z2ram, 128);
  248. #define Z2RAM_START (0x00200000)
  249. #define Z2RAM_END (0x00a00000)
  250. #define Z2RAM_SIZE (0x00800000)
  251. #define Z2RAM_CHUNKSIZE (0x00010000)
  252. #define Z2RAM_CHUNKMASK (0x0000ffff)
  253. #define Z2RAM_CHUNKSHIFT (16)
  254. #endif /* !__ASSEMBLY__ */
  255. #endif /* __KERNEL__ */
  256. #endif /* _LINUX_ZORRO_H */