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 21 #ifndef _LINUX_CS_INTERNAL_H 22 #define _LINUX_CS_INTERNAL_H 23 24 #include <linux/kref.h> 25 26 /* Flags in client state */ 27 #define CLIENT_WIN_REQ(i) (0x1<<(i)) 28 29 /* Each card function gets one of these guys */ 30 typedef struct config_t { 31 struct kref ref; 32 unsigned int state; 33 unsigned int Attributes; 34 unsigned int IntType; 35 unsigned int ConfigBase; 36 unsigned char Status, Pin, Copy, Option, ExtStatus; 37 unsigned int CardValues; 38 io_req_t io; 39 struct { 40 u_int Attributes; 41 } irq; 42 } config_t; 43 44 45 struct cis_cache_entry { 46 struct list_head node; 47 unsigned int addr; 48 unsigned int len; 49 unsigned int attr; 50 unsigned char cache[0]; 51 }; 52 53 struct pccard_resource_ops { 54 int (*validate_mem) (struct pcmcia_socket *s); 55 int (*adjust_io_region) (struct resource *res, 56 unsigned long r_start, 57 unsigned long r_end, 58 struct pcmcia_socket *s); 59 struct resource* (*find_io) (unsigned long base, int num, 60 unsigned long align, 61 struct pcmcia_socket *s); 62 struct resource* (*find_mem) (unsigned long base, unsigned long num, 63 unsigned long align, int low, 64 struct pcmcia_socket *s); 65 int (*add_io) (struct pcmcia_socket *s, 66 unsigned int action, 67 unsigned long r_start, 68 unsigned long r_end); 69 int (*add_mem) (struct pcmcia_socket *s, 70 unsigned int action, 71 unsigned long r_start, 72 unsigned long r_end); 73 int (*init) (struct pcmcia_socket *s); 74 void (*exit) (struct pcmcia_socket *s); 75 }; 76 77 /* Flags in config state */ 78 #define CONFIG_LOCKED 0x01 79 #define CONFIG_IRQ_REQ 0x02 80 #define CONFIG_IO_REQ 0x04 81 82 /* Flags in socket state */ 83 #define SOCKET_PRESENT 0x0008 84 #define SOCKET_INUSE 0x0010 85 #define SOCKET_SUSPEND 0x0080 86 #define SOCKET_WIN_REQ(i) (0x0100<<(i)) 87 #define SOCKET_CARDBUS 0x8000 88 #define SOCKET_CARDBUS_CONFIG 0x10000 89 90 91 /* 92 * Stuff internal to module "pcmcia_core": 93 */ 94 95 /* socket_sysfs.c */ 96 extern int pccard_sysfs_add_socket(struct device *dev); 97 extern void pccard_sysfs_remove_socket(struct device *dev); 98 99 /* cardbus.c */ 100 int cb_alloc(struct pcmcia_socket *s); 101 void cb_free(struct pcmcia_socket *s); 102 103 104 105 /* 106 * Stuff exported by module "pcmcia_core" to module "pcmcia" 107 */ 108 109 struct pcmcia_callback{ 110 struct module *owner; 111 int (*event) (struct pcmcia_socket *s, 112 event_t event, int priority); 113 void (*requery) (struct pcmcia_socket *s); 114 int (*validate) (struct pcmcia_socket *s, unsigned int *i); 115 int (*suspend) (struct pcmcia_socket *s); 116 int (*resume) (struct pcmcia_socket *s); 117 }; 118 119 /* cs.c */ 120 extern struct rw_semaphore pcmcia_socket_list_rwsem; 121 extern struct list_head pcmcia_socket_list; 122 extern struct class pcmcia_socket_class; 123 124 int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c); 125 struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr); 126 127 void pcmcia_parse_uevents(struct pcmcia_socket *socket, unsigned int events); 128 #define PCMCIA_UEVENT_EJECT 0x0001 129 #define PCMCIA_UEVENT_INSERT 0x0002 130 #define PCMCIA_UEVENT_SUSPEND 0x0004 131 #define PCMCIA_UEVENT_RESUME 0x0008 132 #define PCMCIA_UEVENT_REQUERY 0x0010 133 134 struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt); 135 void pcmcia_put_socket(struct pcmcia_socket *skt); 136 137 /* 138 * Stuff internal to module "pcmcia". 139 */ 140 /* ds.c */ 141 extern struct bus_type pcmcia_bus_type; 142 143 /* pcmcia_resource.c */ 144 extern int pcmcia_release_configuration(struct pcmcia_device *p_dev); 145 extern int pcmcia_validate_mem(struct pcmcia_socket *s); 146 extern struct resource *pcmcia_find_mem_region(u_long base, 147 u_long num, 148 u_long align, 149 int low, 150 struct pcmcia_socket *s); 151 152 void pcmcia_cleanup_irq(struct pcmcia_socket *s); 153 int pcmcia_setup_irq(struct pcmcia_device *p_dev); 154 155 /* cistpl.c */ 156 extern struct bin_attribute pccard_cis_attr; 157 158 int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, 159 u_int addr, u_int len, void *ptr); 160 void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, 161 u_int addr, u_int len, void *ptr); 162 void release_cis_mem(struct pcmcia_socket *s); 163 void destroy_cis_cache(struct pcmcia_socket *s); 164 int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, 165 cisdata_t code, void *parse); 166 int pcmcia_replace_cis(struct pcmcia_socket *s, 167 const u8 *data, const size_t len); 168 int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *count); 169 int verify_cis_cache(struct pcmcia_socket *s); 170 171 int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function, 172 cisdata_t code, cisparse_t *parse, void *priv_data, 173 int (*loop_tuple) (tuple_t *tuple, 174 cisparse_t *parse, 175 void *priv_data)); 176 177 int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, 178 tuple_t *tuple); 179 180 int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, 181 tuple_t *tuple); 182 183 int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple); 184 185 186 #ifdef CONFIG_PCMCIA_IOCTL 187 /* ds.c */ 188 extern struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev); 189 extern void pcmcia_put_dev(struct pcmcia_device *p_dev); 190 191 struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, 192 unsigned int function); 193 194 /* pcmcia_ioctl.c */ 195 extern void __init pcmcia_setup_ioctl(void); 196 extern void __exit pcmcia_cleanup_ioctl(void); 197 extern void handle_event(struct pcmcia_socket *s, event_t event); 198 extern int handle_request(struct pcmcia_socket *s, event_t event); 199 200 #else /* CONFIG_PCMCIA_IOCTL */ 201 202 static inline void __init pcmcia_setup_ioctl(void) { return; } 203 static inline void __exit pcmcia_cleanup_ioctl(void) { return; } 204 static inline void handle_event(struct pcmcia_socket *s, event_t event) 205 { 206 return; 207 } 208 static inline int handle_request(struct pcmcia_socket *s, event_t event) 209 { 210 return 0; 211 } 212 213 #endif /* CONFIG_PCMCIA_IOCTL */ 214 215 #endif /* _LINUX_CS_INTERNAL_H */ 216