cs_internal.h revision 91284224da5b15ec6c2b45e10fa5eccd1c92a204
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 */ 30typedef 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 45struct 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 53struct 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 90static inline int cs_socket_get(struct pcmcia_socket *skt) 91{ 92 int ret; 93 94 WARN_ON(skt->state & SOCKET_INUSE); 95 96 ret = try_module_get(skt->owner); 97 if (ret) 98 skt->state |= SOCKET_INUSE; 99 return ret; 100} 101 102static inline void cs_socket_put(struct pcmcia_socket *skt) 103{ 104 if (skt->state & SOCKET_INUSE) { 105 skt->state &= ~SOCKET_INUSE; 106 module_put(skt->owner); 107 } 108} 109 110#ifdef CONFIG_PCMCIA_DEBUG 111extern int cs_debug_level(int); 112 113#define cs_dbg(skt, lvl, fmt, arg...) do { \ 114 if (cs_debug_level(lvl)) \ 115 dev_printk(KERN_DEBUG, &skt->dev, \ 116 "cs: " fmt, ## arg); \ 117} while (0) 118#define __cs_dbg(lvl, fmt, arg...) do { \ 119 if (cs_debug_level(lvl)) \ 120 printk(KERN_DEBUG \ 121 "cs: " fmt, ## arg); \ 122} while (0) 123 124#else 125#define cs_dbg(skt, lvl, fmt, arg...) do { } while (0) 126#define __cs_dbg(lvl, fmt, arg...) do { } while (0) 127#endif 128 129#define cs_err(skt, fmt, arg...) \ 130 dev_printk(KERN_ERR, &skt->dev, "cs: " fmt, ## arg) 131 132 133/* 134 * Stuff internal to module "pcmcia_core": 135 */ 136 137/* cistpl.c */ 138int verify_cis_cache(struct pcmcia_socket *s); 139 140/* rsrc_mgr.c */ 141void release_resource_db(struct pcmcia_socket *s); 142 143/* socket_sysfs.c */ 144extern int pccard_sysfs_add_socket(struct device *dev); 145extern void pccard_sysfs_remove_socket(struct device *dev); 146 147/* cardbus.c */ 148int cb_alloc(struct pcmcia_socket *s); 149void cb_free(struct pcmcia_socket *s); 150int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, 151 void *ptr); 152 153 154 155/* 156 * Stuff exported by module "pcmcia_core" to module "pcmcia" 157 */ 158 159struct pcmcia_callback{ 160 struct module *owner; 161 int (*event) (struct pcmcia_socket *s, 162 event_t event, int priority); 163 void (*requery) (struct pcmcia_socket *s, int new_cis); 164 int (*suspend) (struct pcmcia_socket *s); 165 int (*resume) (struct pcmcia_socket *s); 166}; 167 168/* cs.c */ 169extern struct rw_semaphore pcmcia_socket_list_rwsem; 170extern struct list_head pcmcia_socket_list; 171extern struct class pcmcia_socket_class; 172 173int pcmcia_get_window(struct pcmcia_socket *s, 174 window_handle_t *handle, 175 int idx, 176 win_req_t *req); 177int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c); 178struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr); 179 180int pcmcia_suspend_card(struct pcmcia_socket *skt); 181int pcmcia_resume_card(struct pcmcia_socket *skt); 182 183int pcmcia_eject_card(struct pcmcia_socket *skt); 184int pcmcia_insert_card(struct pcmcia_socket *skt); 185 186struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt); 187void pcmcia_put_socket(struct pcmcia_socket *skt); 188 189/* cistpl.c */ 190int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, 191 u_int addr, u_int len, void *ptr); 192void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, 193 u_int addr, u_int len, void *ptr); 194void release_cis_mem(struct pcmcia_socket *s); 195void destroy_cis_cache(struct pcmcia_socket *s); 196int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, 197 cisdata_t code, void *parse); 198int pcmcia_replace_cis(struct pcmcia_socket *s, 199 const u8 *data, const size_t len); 200int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *count); 201 202/* loop over CIS entries */ 203int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function, 204 cisdata_t code, cisparse_t *parse, void *priv_data, 205 int (*loop_tuple) (tuple_t *tuple, 206 cisparse_t *parse, 207 void *priv_data)); 208 209/* rsrc_mgr.c */ 210int pcmcia_validate_mem(struct pcmcia_socket *s); 211struct resource *pcmcia_find_io_region(unsigned long base, 212 int num, 213 unsigned long align, 214 struct pcmcia_socket *s); 215int pcmcia_adjust_io_region(struct resource *res, 216 unsigned long r_start, 217 unsigned long r_end, 218 struct pcmcia_socket *s); 219struct resource *pcmcia_find_mem_region(u_long base, 220 u_long num, 221 u_long align, 222 int low, 223 struct pcmcia_socket *s); 224 225/* 226 * Stuff internal to module "pcmcia". 227 */ 228/* ds.c */ 229extern struct bus_type pcmcia_bus_type; 230 231/* pcmcia_resource.c */ 232extern int pcmcia_release_configuration(struct pcmcia_device *p_dev); 233 234#ifdef CONFIG_PCMCIA_IOCTL 235/* ds.c */ 236extern spinlock_t pcmcia_dev_list_lock; 237 238extern struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev); 239extern void pcmcia_put_dev(struct pcmcia_device *p_dev); 240 241struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, 242 unsigned int function); 243 244/* pcmcia_ioctl.c */ 245extern void __init pcmcia_setup_ioctl(void); 246extern void __exit pcmcia_cleanup_ioctl(void); 247extern void handle_event(struct pcmcia_socket *s, event_t event); 248extern int handle_request(struct pcmcia_socket *s, event_t event); 249 250#else /* CONFIG_PCMCIA_IOCTL */ 251 252static inline void __init pcmcia_setup_ioctl(void) { return; } 253static inline void __exit pcmcia_cleanup_ioctl(void) { return; } 254static inline void handle_event(struct pcmcia_socket *s, event_t event) 255{ 256 return; 257} 258static inline int handle_request(struct pcmcia_socket *s, event_t event) 259{ 260 return 0; 261} 262 263#endif /* CONFIG_PCMCIA_IOCTL */ 264 265#endif /* _LINUX_CS_INTERNAL_H */ 266