Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 18 | #include <linux/kref.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 26 | #define CLIENT_WIN_REQ(i) (0x1<<(i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #define CLIENT_CARDBUS 0x8000 |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | /* Each card function gets one of these guys */ |
| 30 | typedef struct config_t { |
Dominik Brodowski | 360b65b | 2006-01-10 20:50:39 +0100 | [diff] [blame] | 31 | struct kref ref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | u_int state; |
| 33 | u_int Attributes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | u_int IntType; |
| 35 | u_int ConfigBase; |
| 36 | u_char Status, Pin, Copy, Option, ExtStatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | u_int CardValues; |
| 38 | io_req_t io; |
| 39 | struct { |
| 40 | u_int Attributes; |
| 41 | } irq; |
| 42 | } config_t; |
| 43 | |
| 44 | struct cis_cache_entry { |
| 45 | struct list_head node; |
| 46 | unsigned int addr; |
| 47 | unsigned int len; |
| 48 | unsigned int attr; |
| 49 | unsigned char cache[0]; |
| 50 | }; |
| 51 | |
| 52 | /* Flags in config state */ |
| 53 | #define CONFIG_LOCKED 0x01 |
| 54 | #define CONFIG_IRQ_REQ 0x02 |
| 55 | #define CONFIG_IO_REQ 0x04 |
| 56 | |
| 57 | /* Flags in socket state */ |
| 58 | #define SOCKET_PRESENT 0x0008 |
| 59 | #define SOCKET_INUSE 0x0010 |
| 60 | #define SOCKET_SUSPEND 0x0080 |
| 61 | #define SOCKET_WIN_REQ(i) (0x0100<<(i)) |
| 62 | #define SOCKET_REGION_INFO 0x4000 |
| 63 | #define SOCKET_CARDBUS 0x8000 |
| 64 | #define SOCKET_CARDBUS_CONFIG 0x10000 |
| 65 | |
| 66 | static inline int cs_socket_get(struct pcmcia_socket *skt) |
| 67 | { |
| 68 | int ret; |
| 69 | |
| 70 | WARN_ON(skt->state & SOCKET_INUSE); |
| 71 | |
| 72 | ret = try_module_get(skt->owner); |
| 73 | if (ret) |
| 74 | skt->state |= SOCKET_INUSE; |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | static inline void cs_socket_put(struct pcmcia_socket *skt) |
| 79 | { |
| 80 | if (skt->state & SOCKET_INUSE) { |
| 81 | skt->state &= ~SOCKET_INUSE; |
| 82 | module_put(skt->owner); |
| 83 | } |
| 84 | } |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* In cardbus.c */ |
| 87 | int cb_alloc(struct pcmcia_socket *s); |
| 88 | void cb_free(struct pcmcia_socket *s); |
| 89 | int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, void *ptr); |
| 90 | |
| 91 | /* In cistpl.c */ |
Dominik Brodowski | e6ea0b9e | 2005-06-27 16:28:52 -0700 | [diff] [blame] | 92 | int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | u_int addr, u_int len, void *ptr); |
Dominik Brodowski | e6ea0b9e | 2005-06-27 16:28:52 -0700 | [diff] [blame] | 94 | void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | u_int addr, u_int len, void *ptr); |
| 96 | void release_cis_mem(struct pcmcia_socket *s); |
| 97 | void destroy_cis_cache(struct pcmcia_socket *s); |
| 98 | int verify_cis_cache(struct pcmcia_socket *s); |
| 99 | int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t code, void *parse); |
| 100 | |
| 101 | /* In rsrc_mgr */ |
Dominik Brodowski | de75914 | 2005-09-28 19:41:56 +0200 | [diff] [blame] | 102 | int pcmcia_validate_mem(struct pcmcia_socket *s); |
Dominik Brodowski | e6ea0b9e | 2005-06-27 16:28:52 -0700 | [diff] [blame] | 103 | struct resource *pcmcia_find_io_region(unsigned long base, int num, unsigned long align, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | struct pcmcia_socket *s); |
Dominik Brodowski | e6ea0b9e | 2005-06-27 16:28:52 -0700 | [diff] [blame] | 105 | int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | unsigned long r_end, struct pcmcia_socket *s); |
Dominik Brodowski | e6ea0b9e | 2005-06-27 16:28:52 -0700 | [diff] [blame] | 107 | struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | int low, struct pcmcia_socket *s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | void release_resource_db(struct pcmcia_socket *s); |
| 110 | |
| 111 | /* In socket_sysfs.c */ |
David Brownell | 4356d73 | 2008-04-28 01:03:20 -0700 | [diff] [blame] | 112 | extern int pccard_sysfs_add_socket(struct device *dev); |
| 113 | extern void pccard_sysfs_remove_socket(struct device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
| 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); |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 119 | int pccard_get_configuration_info(struct pcmcia_socket *s, struct pcmcia_device *p_dev, config_info_t *config); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | int pccard_reset_card(struct pcmcia_socket *skt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | |
| 123 | struct pcmcia_callback{ |
| 124 | struct module *owner; |
| 125 | int (*event) (struct pcmcia_socket *s, event_t event, int priority); |
Dominik Brodowski | 4ae1cbf | 2006-11-03 10:54:00 -0500 | [diff] [blame] | 126 | void (*requery) (struct pcmcia_socket *s, int new_cis); |
Dominik Brodowski | 8e9e793 | 2006-01-06 00:02:03 +0100 | [diff] [blame] | 127 | int (*suspend) (struct pcmcia_socket *s); |
| 128 | int (*resume) (struct pcmcia_socket *s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c); |
| 132 | |
Dominik Brodowski | 7d16b65 | 2008-08-02 21:02:01 +0200 | [diff] [blame^] | 133 | #ifdef CONFIG_PCMCIA_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | extern int cs_debug_level(int); |
| 135 | |
| 136 | #define cs_dbg(skt, lvl, fmt, arg...) do { \ |
| 137 | if (cs_debug_level(lvl)) \ |
Dominik Brodowski | 2e55bf6 | 2008-08-02 18:08:38 +0200 | [diff] [blame] | 138 | dev_printk(KERN_DEBUG, &skt->dev, \ |
| 139 | "cs: " fmt, ## arg); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } while (0) |
| 141 | |
| 142 | #else |
| 143 | #define cs_dbg(skt, lvl, fmt, arg...) do { } while (0) |
| 144 | #endif |
| 145 | |
| 146 | #define cs_err(skt, fmt, arg...) \ |
Dominik Brodowski | 2e55bf6 | 2008-08-02 18:08:38 +0200 | [diff] [blame] | 147 | dev_printk(KERN_ERR, &skt->dev, "cs: " fmt, ## arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | #endif /* _LINUX_CS_INTERNAL_H */ |