cs_internal.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * cs_internal.h -- definitions internal to the PCMCIA core modules
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * The initial developer of the original code is David A. Hinds
  9. * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
  10. * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  11. *
  12. * (C) 1999 David A. Hinds
  13. * (C) 2003 - 2008 Dominik Brodowski
  14. *
  15. *
  16. * This file contains definitions _only_ needed by the PCMCIA core modules.
  17. * It must not be included by PCMCIA socket drivers or by PCMCIA device
  18. * drivers.
  19. */
  20. #ifndef _LINUX_CS_INTERNAL_H
  21. #define _LINUX_CS_INTERNAL_H
  22. #include <linux/kref.h>
  23. /* Flags in client state */
  24. #define CLIENT_WIN_REQ(i) (0x1<<(i))
  25. /* Each card function gets one of these guys */
  26. typedef struct config_t {
  27. struct kref ref;
  28. unsigned int state;
  29. unsigned int Attributes;
  30. unsigned int IntType;
  31. unsigned int ConfigBase;
  32. unsigned char Status, Pin, Copy, Option, ExtStatus;
  33. unsigned int CardValues;
  34. io_req_t io;
  35. struct {
  36. u_int Attributes;
  37. } irq;
  38. } config_t;
  39. struct cis_cache_entry {
  40. struct list_head node;
  41. unsigned int addr;
  42. unsigned int len;
  43. unsigned int attr;
  44. unsigned char cache[0];
  45. };
  46. struct pccard_resource_ops {
  47. int (*validate_mem) (struct pcmcia_socket *s);
  48. int (*adjust_io_region) (struct resource *res,
  49. unsigned long r_start,
  50. unsigned long r_end,
  51. struct pcmcia_socket *s);
  52. struct resource* (*find_io) (unsigned long base, int num,
  53. unsigned long align,
  54. struct pcmcia_socket *s);
  55. struct resource* (*find_mem) (unsigned long base, unsigned long num,
  56. unsigned long align, int low,
  57. struct pcmcia_socket *s);
  58. int (*add_io) (struct pcmcia_socket *s,
  59. unsigned int action,
  60. unsigned long r_start,
  61. unsigned long r_end);
  62. int (*add_mem) (struct pcmcia_socket *s,
  63. unsigned int action,
  64. unsigned long r_start,
  65. unsigned long r_end);
  66. int (*init) (struct pcmcia_socket *s);
  67. void (*exit) (struct pcmcia_socket *s);
  68. };
  69. /* Flags in config state */
  70. #define CONFIG_LOCKED 0x01
  71. #define CONFIG_IRQ_REQ 0x02
  72. #define CONFIG_IO_REQ 0x04
  73. /* Flags in socket state */
  74. #define SOCKET_PRESENT 0x0008
  75. #define SOCKET_INUSE 0x0010
  76. #define SOCKET_SUSPEND 0x0080
  77. #define SOCKET_WIN_REQ(i) (0x0100<<(i))
  78. #define SOCKET_CARDBUS 0x8000
  79. #define SOCKET_CARDBUS_CONFIG 0x10000
  80. static inline int cs_socket_get(struct pcmcia_socket *skt)
  81. {
  82. int ret;
  83. WARN_ON(skt->state & SOCKET_INUSE);
  84. ret = try_module_get(skt->owner);
  85. if (ret)
  86. skt->state |= SOCKET_INUSE;
  87. return ret;
  88. }
  89. static inline void cs_socket_put(struct pcmcia_socket *skt)
  90. {
  91. if (skt->state & SOCKET_INUSE) {
  92. skt->state &= ~SOCKET_INUSE;
  93. module_put(skt->owner);
  94. }
  95. }
  96. #ifdef CONFIG_PCMCIA_DEBUG
  97. extern int cs_debug_level(int);
  98. #define cs_dbg(skt, lvl, fmt, arg...) do { \
  99. if (cs_debug_level(lvl)) \
  100. dev_printk(KERN_DEBUG, &skt->dev, \
  101. "cs: " fmt, ## arg); \
  102. } while (0)
  103. #define __cs_dbg(lvl, fmt, arg...) do { \
  104. if (cs_debug_level(lvl)) \
  105. printk(KERN_DEBUG \
  106. "cs: " fmt, ## arg); \
  107. } while (0)
  108. #else
  109. #define cs_dbg(skt, lvl, fmt, arg...) do { } while (0)
  110. #define __cs_dbg(lvl, fmt, arg...) do { } while (0)
  111. #endif
  112. #define cs_err(skt, fmt, arg...) \
  113. dev_printk(KERN_ERR, &skt->dev, "cs: " fmt, ## arg)
  114. /*
  115. * Stuff internal to module "pcmcia_core":
  116. */
  117. /* cistpl.c */
  118. int verify_cis_cache(struct pcmcia_socket *s);
  119. /* rsrc_mgr.c */
  120. void release_resource_db(struct pcmcia_socket *s);
  121. /* socket_sysfs.c */
  122. extern int pccard_sysfs_add_socket(struct device *dev);
  123. extern void pccard_sysfs_remove_socket(struct device *dev);
  124. /* cardbus.c */
  125. int cb_alloc(struct pcmcia_socket *s);
  126. void cb_free(struct pcmcia_socket *s);
  127. int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len,
  128. void *ptr);
  129. /*
  130. * Stuff exported by module "pcmcia_core" to module "pcmcia"
  131. */
  132. struct pcmcia_callback{
  133. struct module *owner;
  134. int (*event) (struct pcmcia_socket *s,
  135. event_t event, int priority);
  136. void (*requery) (struct pcmcia_socket *s, int new_cis);
  137. int (*suspend) (struct pcmcia_socket *s);
  138. int (*resume) (struct pcmcia_socket *s);
  139. };
  140. /* cs.c */
  141. extern struct rw_semaphore pcmcia_socket_list_rwsem;
  142. extern struct list_head pcmcia_socket_list;
  143. extern struct class pcmcia_socket_class;
  144. int pcmcia_get_window(struct pcmcia_socket *s,
  145. window_handle_t *handle,
  146. int idx,
  147. win_req_t *req);
  148. int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
  149. struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr);
  150. int pcmcia_suspend_card(struct pcmcia_socket *skt);
  151. int pcmcia_resume_card(struct pcmcia_socket *skt);
  152. int pcmcia_eject_card(struct pcmcia_socket *skt);
  153. int pcmcia_insert_card(struct pcmcia_socket *skt);
  154. struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt);
  155. void pcmcia_put_socket(struct pcmcia_socket *skt);
  156. /* cistpl.c */
  157. int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr,
  158. u_int addr, u_int len, void *ptr);
  159. void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr,
  160. u_int addr, u_int len, void *ptr);
  161. void release_cis_mem(struct pcmcia_socket *s);
  162. void destroy_cis_cache(struct pcmcia_socket *s);
  163. int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function,
  164. cisdata_t code, void *parse);
  165. int pcmcia_replace_cis(struct pcmcia_socket *s,
  166. const u8 *data, const size_t len);
  167. int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function,
  168. unsigned int *count);
  169. /* rsrc_mgr.c */
  170. int pcmcia_validate_mem(struct pcmcia_socket *s);
  171. struct resource *pcmcia_find_io_region(unsigned long base,
  172. int num,
  173. unsigned long align,
  174. struct pcmcia_socket *s);
  175. int pcmcia_adjust_io_region(struct resource *res,
  176. unsigned long r_start,
  177. unsigned long r_end,
  178. struct pcmcia_socket *s);
  179. struct resource *pcmcia_find_mem_region(u_long base,
  180. u_long num,
  181. u_long align,
  182. int low,
  183. struct pcmcia_socket *s);
  184. /*
  185. * Stuff internal to module "pcmcia".
  186. */
  187. /* ds.c */
  188. extern struct bus_type pcmcia_bus_type;
  189. /* pcmcia_resource.c */
  190. extern int pcmcia_release_configuration(struct pcmcia_device *p_dev);
  191. #ifdef CONFIG_PCMCIA_IOCTL
  192. /* ds.c */
  193. extern spinlock_t pcmcia_dev_list_lock;
  194. extern struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev);
  195. extern void pcmcia_put_dev(struct pcmcia_device *p_dev);
  196. struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s,
  197. unsigned int function);
  198. /* pcmcia_ioctl.c */
  199. extern void __init pcmcia_setup_ioctl(void);
  200. extern void __exit pcmcia_cleanup_ioctl(void);
  201. extern void handle_event(struct pcmcia_socket *s, event_t event);
  202. extern int handle_request(struct pcmcia_socket *s, event_t event);
  203. #else /* CONFIG_PCMCIA_IOCTL */
  204. static inline void __init pcmcia_setup_ioctl(void) { return; }
  205. static inline void __exit pcmcia_cleanup_ioctl(void) { return; }
  206. static inline void handle_event(struct pcmcia_socket *s, event_t event)
  207. {
  208. return;
  209. }
  210. static inline int handle_request(struct pcmcia_socket *s, event_t event)
  211. {
  212. return 0;
  213. }
  214. #endif /* CONFIG_PCMCIA_IOCTL */
  215. #endif /* _LINUX_CS_INTERNAL_H */