cs_internal.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * cs_internal.h
  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. */
  14. #ifndef _LINUX_CS_INTERNAL_H
  15. #define _LINUX_CS_INTERNAL_H
  16. #include <linux/config.h>
  17. #define CLIENT_MAGIC 0x51E6
  18. typedef struct client_t client_t;
  19. /* Flags in client state */
  20. #define CLIENT_CONFIG_LOCKED 0x0001
  21. #define CLIENT_IRQ_REQ 0x0002
  22. #define CLIENT_IO_REQ 0x0004
  23. #define CLIENT_UNBOUND 0x0008
  24. #define CLIENT_STALE 0x0010
  25. #define CLIENT_WIN_REQ(i) (0x20<<(i))
  26. #define CLIENT_CARDBUS 0x8000
  27. #define REGION_MAGIC 0xE3C9
  28. typedef struct region_t {
  29. u_short region_magic;
  30. u_short state;
  31. dev_info_t dev_info;
  32. client_handle_t mtd;
  33. u_int MediaID;
  34. region_info_t info;
  35. } region_t;
  36. #define REGION_STALE 0x01
  37. /* Each card function gets one of these guys */
  38. typedef struct config_t {
  39. u_int state;
  40. u_int Attributes;
  41. u_int Vcc, Vpp1, Vpp2;
  42. u_int IntType;
  43. u_int ConfigBase;
  44. u_char Status, Pin, Copy, Option, ExtStatus;
  45. u_int Present;
  46. u_int CardValues;
  47. io_req_t io;
  48. struct {
  49. u_int Attributes;
  50. } irq;
  51. } config_t;
  52. struct cis_cache_entry {
  53. struct list_head node;
  54. unsigned int addr;
  55. unsigned int len;
  56. unsigned int attr;
  57. unsigned char cache[0];
  58. };
  59. /* Flags in config state */
  60. #define CONFIG_LOCKED 0x01
  61. #define CONFIG_IRQ_REQ 0x02
  62. #define CONFIG_IO_REQ 0x04
  63. /* Flags in socket state */
  64. #define SOCKET_PRESENT 0x0008
  65. #define SOCKET_INUSE 0x0010
  66. #define SOCKET_SUSPEND 0x0080
  67. #define SOCKET_WIN_REQ(i) (0x0100<<(i))
  68. #define SOCKET_REGION_INFO 0x4000
  69. #define SOCKET_CARDBUS 0x8000
  70. #define SOCKET_CARDBUS_CONFIG 0x10000
  71. static inline int cs_socket_get(struct pcmcia_socket *skt)
  72. {
  73. int ret;
  74. WARN_ON(skt->state & SOCKET_INUSE);
  75. ret = try_module_get(skt->owner);
  76. if (ret)
  77. skt->state |= SOCKET_INUSE;
  78. return ret;
  79. }
  80. static inline void cs_socket_put(struct pcmcia_socket *skt)
  81. {
  82. if (skt->state & SOCKET_INUSE) {
  83. skt->state &= ~SOCKET_INUSE;
  84. module_put(skt->owner);
  85. }
  86. }
  87. #define CHECK_HANDLE(h) \
  88. (((h) == NULL) || ((h)->client_magic != CLIENT_MAGIC))
  89. #define CHECK_SOCKET(s) \
  90. (((s) >= sockets) || (socket_table[s]->ops == NULL))
  91. #define SOCKET(h) (h->Socket)
  92. #define CONFIG(h) (&SOCKET(h)->config[(h)->Function])
  93. #define CHECK_REGION(r) \
  94. (((r) == NULL) || ((r)->region_magic != REGION_MAGIC))
  95. #define CHECK_ERASEQ(q) \
  96. (((q) == NULL) || ((q)->eraseq_magic != ERASEQ_MAGIC))
  97. #define EVENT(h, e, p) \
  98. ((h)->event_handler((e), (p), &(h)->event_callback_args))
  99. /* In cardbus.c */
  100. int cb_alloc(struct pcmcia_socket *s);
  101. void cb_free(struct pcmcia_socket *s);
  102. int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, void *ptr);
  103. /* In cistpl.c */
  104. int read_cis_mem(struct pcmcia_socket *s, int attr,
  105. u_int addr, u_int len, void *ptr);
  106. void write_cis_mem(struct pcmcia_socket *s, int attr,
  107. u_int addr, u_int len, void *ptr);
  108. void release_cis_mem(struct pcmcia_socket *s);
  109. void destroy_cis_cache(struct pcmcia_socket *s);
  110. int verify_cis_cache(struct pcmcia_socket *s);
  111. int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t code, void *parse);
  112. /* In rsrc_mgr */
  113. void pcmcia_validate_mem(struct pcmcia_socket *s);
  114. struct resource *find_io_region(unsigned long base, int num, unsigned long align,
  115. struct pcmcia_socket *s);
  116. int adjust_io_region(struct resource *res, unsigned long r_start,
  117. unsigned long r_end, struct pcmcia_socket *s);
  118. struct resource *find_mem_region(u_long base, u_long num, u_long align,
  119. int low, struct pcmcia_socket *s);
  120. int adjust_resource_info(client_handle_t handle, adjust_t *adj);
  121. void release_resource_db(struct pcmcia_socket *s);
  122. /* In socket_sysfs.c */
  123. extern struct class_interface pccard_sysfs_interface;
  124. /* In cs.c */
  125. extern struct rw_semaphore pcmcia_socket_list_rwsem;
  126. extern struct list_head pcmcia_socket_list;
  127. int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req);
  128. int pccard_get_configuration_info(struct pcmcia_socket *s, unsigned int function, config_info_t *config);
  129. int pccard_reset_card(struct pcmcia_socket *skt);
  130. int pccard_get_status(struct pcmcia_socket *s, unsigned int function, cs_status_t *status);
  131. int pccard_access_configuration_register(struct pcmcia_socket *s, unsigned int function, conf_reg_t *reg);
  132. struct pcmcia_callback{
  133. struct module *owner;
  134. int (*event) (struct pcmcia_socket *s, event_t event, int priority);
  135. int (*resources_done) (struct pcmcia_socket *s);
  136. void (*replace_cis) (void);
  137. };
  138. int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
  139. #define cs_socket_name(skt) ((skt)->dev.class_id)
  140. #ifdef DEBUG
  141. extern int cs_debug_level(int);
  142. #define cs_dbg(skt, lvl, fmt, arg...) do { \
  143. if (cs_debug_level(lvl)) \
  144. printk(KERN_DEBUG "cs: %s: " fmt, \
  145. cs_socket_name(skt) , ## arg); \
  146. } while (0)
  147. #else
  148. #define cs_dbg(skt, lvl, fmt, arg...) do { } while (0)
  149. #endif
  150. #define cs_err(skt, fmt, arg...) \
  151. printk(KERN_ERR "cs: %s: " fmt, (skt)->dev.class_id , ## arg)
  152. #endif /* _LINUX_CS_INTERNAL_H */