cs_internal.h 4.8 KB

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