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