cs_internal.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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_SOCKET(s) \
  88. (((s) >= sockets) || (socket_table[s]->ops == NULL))
  89. #define SOCKET(h) (h->socket)
  90. #define CONFIG(h) (&SOCKET(h)->config[(h)->func])
  91. /* In cardbus.c */
  92. int cb_alloc(struct pcmcia_socket *s);
  93. void cb_free(struct pcmcia_socket *s);
  94. int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, void *ptr);
  95. /* In cistpl.c */
  96. int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr,
  97. u_int addr, u_int len, void *ptr);
  98. void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr,
  99. u_int addr, u_int len, void *ptr);
  100. void release_cis_mem(struct pcmcia_socket *s);
  101. void destroy_cis_cache(struct pcmcia_socket *s);
  102. int verify_cis_cache(struct pcmcia_socket *s);
  103. int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t code, void *parse);
  104. /* In rsrc_mgr */
  105. void pcmcia_validate_mem(struct pcmcia_socket *s);
  106. struct resource *pcmcia_find_io_region(unsigned long base, int num, unsigned long align,
  107. struct pcmcia_socket *s);
  108. int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start,
  109. unsigned long r_end, struct pcmcia_socket *s);
  110. struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
  111. int low, struct pcmcia_socket *s);
  112. void release_resource_db(struct pcmcia_socket *s);
  113. /* In socket_sysfs.c */
  114. extern struct class_interface pccard_sysfs_interface;
  115. /* In cs.c */
  116. extern struct rw_semaphore pcmcia_socket_list_rwsem;
  117. extern struct list_head pcmcia_socket_list;
  118. int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req);
  119. int pccard_get_configuration_info(struct pcmcia_socket *s, unsigned int function, config_info_t *config);
  120. int pccard_reset_card(struct pcmcia_socket *skt);
  121. int pccard_get_status(struct pcmcia_socket *s, unsigned int function, cs_status_t *status);
  122. int pccard_access_configuration_register(struct pcmcia_socket *s, unsigned int function, conf_reg_t *reg);
  123. struct pcmcia_callback{
  124. struct module *owner;
  125. int (*event) (struct pcmcia_socket *s, event_t event, int priority);
  126. void (*requery) (struct pcmcia_socket *s);
  127. };
  128. int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
  129. #define cs_socket_name(skt) ((skt)->dev.class_id)
  130. #ifdef DEBUG
  131. extern int cs_debug_level(int);
  132. #define cs_dbg(skt, lvl, fmt, arg...) do { \
  133. if (cs_debug_level(lvl)) \
  134. printk(KERN_DEBUG "cs: %s: " fmt, \
  135. cs_socket_name(skt) , ## arg); \
  136. } while (0)
  137. #else
  138. #define cs_dbg(skt, lvl, fmt, arg...) do { } while (0)
  139. #endif
  140. #define cs_err(skt, fmt, arg...) \
  141. printk(KERN_ERR "cs: %s: " fmt, (skt)->dev.class_id , ## arg)
  142. #endif /* _LINUX_CS_INTERNAL_H */