pcmciavar.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /* $OpenBSD: pcmciavar.h,v 1.21 2010/09/04 12:59:27 miod Exp $ */
  2. /* $NetBSD: pcmciavar.h,v 1.5 1998/07/19 17:28:17 christos Exp $ */
  3. /*
  4. * Copyright (c) 1997 Marc Horowitz. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. All advertising materials mentioning features or use of this software
  15. * must display the following acknowledgement:
  16. * This product includes software developed by Marc Horowitz.
  17. * 4. The name of the author may not be used to endorse or promote products
  18. * derived from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  21. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  22. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  29. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #include <sys/types.h>
  32. #include <sys/queue.h>
  33. #include <machine/bus.h>
  34. #include <dev/pcmcia/pcmciachip.h>
  35. extern int pcmcia_verbose;
  36. /*
  37. * Contains information about mapped/allocated i/o spaces.
  38. */
  39. struct pcmcia_io_handle {
  40. bus_space_tag_t iot; /* bus space tag (from chipset) */
  41. bus_space_handle_t ioh; /* mapped space handle */
  42. bus_addr_t addr; /* resulting address in bus space */
  43. bus_size_t size; /* size of i/o space */
  44. int flags; /* misc. information */
  45. };
  46. #define PCMCIA_IO_ALLOCATED 0x01 /* i/o space was allocated */
  47. /*
  48. * Contains information about allocated memory space.
  49. */
  50. struct pcmcia_mem_handle {
  51. bus_space_tag_t memt; /* bus space tag (from chipset) */
  52. bus_space_handle_t memh; /* mapped space handle */
  53. bus_addr_t addr; /* resulting address in bus space */
  54. bus_size_t size; /* size of mem space */
  55. pcmcia_mem_handle_t mhandle; /* opaque memory handle */
  56. bus_size_t realsize; /* how much we really allocated */
  57. };
  58. /* pcmcia itself */
  59. #define PCMCIA_CFE_MWAIT_REQUIRED 0x0001
  60. #define PCMCIA_CFE_RDYBSY_ACTIVE 0x0002
  61. #define PCMCIA_CFE_WP_ACTIVE 0x0004
  62. #define PCMCIA_CFE_BVD_ACTIVE 0x0008
  63. #define PCMCIA_CFE_IO8 0x0010
  64. #define PCMCIA_CFE_IO16 0x0020
  65. #define PCMCIA_CFE_IRQSHARE 0x0040
  66. #define PCMCIA_CFE_IRQPULSE 0x0080
  67. #define PCMCIA_CFE_IRQLEVEL 0x0100
  68. #define PCMCIA_CFE_POWERDOWN 0x0200
  69. #define PCMCIA_CFE_READONLY 0x0400
  70. #define PCMCIA_CFE_AUDIO 0x0800
  71. struct pcmcia_config_entry {
  72. int number;
  73. u_int32_t flags;
  74. int iftype;
  75. int num_iospace;
  76. /*
  77. * The card will only decode this mask in any case, so we can
  78. * do dynamic allocation with this in mind, in case the suggestions
  79. * below are no good.
  80. */
  81. u_long iomask;
  82. struct {
  83. u_long length;
  84. u_long start;
  85. } iospace[4]; /* XXX this could be as high as 16 */
  86. u_int16_t irqmask;
  87. int num_memspace;
  88. struct {
  89. u_long length;
  90. u_long cardaddr;
  91. u_long hostaddr;
  92. } memspace[2]; /* XXX this could be as high as 8 */
  93. int maxtwins;
  94. SIMPLEQ_ENTRY(pcmcia_config_entry) cfe_list;
  95. };
  96. struct pcmcia_function {
  97. /* read off the card */
  98. int number;
  99. int function;
  100. int last_config_index;
  101. u_long ccr_base;
  102. u_long ccr_mask;
  103. SIMPLEQ_HEAD(, pcmcia_config_entry) cfe_head;
  104. SIMPLEQ_ENTRY(pcmcia_function) pf_list;
  105. /* run-time state */
  106. struct pcmcia_softc *sc;
  107. struct device *child;
  108. struct pcmcia_config_entry *cfe;
  109. struct pcmcia_mem_handle pf_pcmh;
  110. #define pf_ccrt pf_pcmh.memt
  111. #define pf_ccrh pf_pcmh.memh
  112. #define pf_ccr_mhandle pf_pcmh.mhandle
  113. #define pf_ccr_realsize pf_pcmh.realsize
  114. bus_size_t pf_ccr_offset;
  115. int pf_ccr_window;
  116. bus_addr_t pf_mfc_iobase;
  117. bus_addr_t pf_mfc_iomax;
  118. int (*ih_fct)(void *);
  119. void *ih_arg;
  120. int ih_ipl;
  121. int pf_flags;
  122. };
  123. /* pf_flags */
  124. #define PFF_ENABLED 0x0001 /* function is enabled */
  125. #define PFF_FAKE 0x0002 /* function is made up (no CIS) */
  126. struct pcmcia_card {
  127. int cis1_major;
  128. int cis1_minor;
  129. /* XXX waste of space? */
  130. char cis1_info_buf[256];
  131. char *cis1_info[4];
  132. u_int16_t manufacturer;
  133. #define PCMCIA_VENDOR_INVALID 0xffff
  134. u_int16_t product;
  135. #define PCMCIA_PRODUCT_INVALID 0xffff
  136. u_int16_t error;
  137. #define PCMCIA_CIS_INVALID { NULL, NULL, NULL, NULL }
  138. SIMPLEQ_HEAD(, pcmcia_function) pf_head;
  139. };
  140. struct pcmcia_softc {
  141. struct device dev;
  142. /* this stuff is for the socket */
  143. pcmcia_chipset_tag_t pct;
  144. pcmcia_chipset_handle_t pch;
  145. /* this stuff is for the card */
  146. struct pcmcia_card card;
  147. void *ih;
  148. int sc_enabled_count; /* how many functions are
  149. enabled */
  150. /*
  151. * These are passed down from the PCMCIA chip, and exist only
  152. * so that cards with Very Special address allocation needs
  153. * know what range they should be dealing with.
  154. */
  155. bus_addr_t iobase; /* start i/o space allocation here */
  156. bus_size_t iosize; /* size of the i/o space range */
  157. };
  158. struct pcmcia_cis_quirk {
  159. u_int16_t manufacturer;
  160. u_int16_t product;
  161. char *cis1_info[4];
  162. struct pcmcia_function *pf;
  163. struct pcmcia_config_entry *cfe;
  164. };
  165. struct pcmcia_attach_args {
  166. u_int16_t manufacturer;
  167. u_int16_t product;
  168. struct pcmcia_card *card;
  169. struct pcmcia_function *pf;
  170. };
  171. struct pcmcia_tuple {
  172. unsigned int code;
  173. unsigned int length;
  174. unsigned int addrshift;
  175. unsigned int flags;
  176. #define PTF_INDIRECT 0x01
  177. bus_size_t indirect_ptr;
  178. bus_size_t ptr;
  179. bus_space_tag_t memt;
  180. bus_space_handle_t memh;
  181. };
  182. void pcmcia_read_cis(struct pcmcia_softc *);
  183. void pcmcia_check_cis_quirks(struct pcmcia_softc *);
  184. void pcmcia_print_cis(struct pcmcia_softc *);
  185. int pcmcia_scan_cis(struct device * dev,
  186. int (*) (struct pcmcia_tuple *, void *), void *);
  187. uint8_t pcmcia_cis_read_1(struct pcmcia_tuple *, bus_size_t);
  188. #define pcmcia_tuple_read_1(tuple, idx1) \
  189. (pcmcia_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
  190. #define pcmcia_tuple_read_2(tuple, idx2) \
  191. (pcmcia_tuple_read_1((tuple), (idx2)) | \
  192. (pcmcia_tuple_read_1((tuple), (idx2)+1)<<8))
  193. #define pcmcia_tuple_read_3(tuple, idx3) \
  194. (pcmcia_tuple_read_1((tuple), (idx3)) | \
  195. (pcmcia_tuple_read_1((tuple), (idx3)+1)<<8) | \
  196. (pcmcia_tuple_read_1((tuple), (idx3)+2)<<16))
  197. #define pcmcia_tuple_read_4(tuple, idx4) \
  198. (pcmcia_tuple_read_1((tuple), (idx4)) | \
  199. (pcmcia_tuple_read_1((tuple), (idx4)+1)<<8) | \
  200. (pcmcia_tuple_read_1((tuple), (idx4)+2)<<16) | \
  201. (pcmcia_tuple_read_1((tuple), (idx4)+3)<<24))
  202. #define pcmcia_tuple_read_n(tuple, n, idxn) \
  203. (((n)==1)?pcmcia_tuple_read_1((tuple), (idxn)) : \
  204. (((n)==2)?pcmcia_tuple_read_2((tuple), (idxn)) : \
  205. (((n)==3)?pcmcia_tuple_read_3((tuple), (idxn)) : \
  206. /* n == 4 */ pcmcia_tuple_read_4((tuple), (idxn)))))
  207. #define PCMCIA_SPACE_MEMORY 1
  208. #define PCMCIA_SPACE_IO 2
  209. int pcmcia_ccr_read(struct pcmcia_function *, int);
  210. void pcmcia_ccr_write(struct pcmcia_function *, int, int);
  211. #define pcmcia_mfc(sc) (SIMPLEQ_FIRST(&(sc)->card.pf_head) && \
  212. SIMPLEQ_NEXT(SIMPLEQ_FIRST(&(sc)->card.pf_head), pf_list))
  213. void pcmcia_function_init(struct pcmcia_function *,
  214. struct pcmcia_config_entry *);
  215. int pcmcia_function_enable(struct pcmcia_function *);
  216. void pcmcia_function_disable(struct pcmcia_function *);
  217. #define pcmcia_io_alloc(pf, start, size, align, pciop) \
  218. (pcmcia_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start), \
  219. (size), (align), (pciop)))
  220. int pcmcia_io_map(struct pcmcia_function *, int, bus_addr_t,
  221. bus_size_t, struct pcmcia_io_handle *, int *);
  222. #define pcmcia_io_unmap(pf, window) \
  223. (pcmcia_chip_io_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
  224. #define pcmcia_io_free(pf, pciop) \
  225. (pcmcia_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciop)))
  226. #define pcmcia_mem_alloc(pf, size, pcmhp) \
  227. (pcmcia_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
  228. #define pcmcia_mem_free(pf, pcmhp) \
  229. (pcmcia_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
  230. #define pcmcia_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
  231. (pcmcia_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind), \
  232. (card_addr), (size), (pcmhp), (offsetp), (windowp)))
  233. #define pcmcia_mem_unmap(pf, window) \
  234. (pcmcia_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
  235. void *pcmcia_intr_establish(struct pcmcia_function *, int,
  236. int (*) (void *), void *, char *);
  237. void pcmcia_intr_disestablish(struct pcmcia_function *, void *);
  238. const char *pcmcia_intr_string(struct pcmcia_function *, void *);