blob: 03ec438029092a89987e68fb6550a75b88c444df [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Dominik Brodowskidc953e52008-08-25 23:18:20 +02002 * cs_internal.h -- definitions internal to the PCMCIA core modules
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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
Dominik Brodowski7b24e792010-07-11 10:26:53 +020013 * (C) 2003 - 2010 Dominik Brodowski
Dominik Brodowskidc953e52008-08-25 23:18:20 +020014 *
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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 */
20
21#ifndef _LINUX_CS_INTERNAL_H
22#define _LINUX_CS_INTERNAL_H
23
Dominik Brodowski360b65b2006-01-10 20:50:39 +010024#include <linux/kref.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026/* Flags in client state */
Dominik Brodowskie2d40962006-03-02 00:09:29 +010027#define CLIENT_WIN_REQ(i) (0x1<<(i))
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Dominik Brodowskia3d0d4d2010-07-24 17:43:10 +020029/* Flag to access all functions */
30#define BIND_FN_ALL 0xff
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/* Each card function gets one of these guys */
33typedef struct config_t {
Dominik Brodowski360b65b2006-01-10 20:50:39 +010034 struct kref ref;
Dominik Brodowskidc953e52008-08-25 23:18:20 +020035 unsigned int state;
Dominik Brodowski2ce49052010-07-24 13:14:44 +020036
37 struct resource io[MAX_IO_WIN]; /* io ports */
Dominik Brodowski0ca724d32010-07-24 19:03:02 +020038 struct resource mem[MAX_WIN]; /* mem areas */
Linus Torvalds1da177e2005-04-16 15:20:36 -070039} config_t;
40
Dominik Brodowskidc953e52008-08-25 23:18:20 +020041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042struct cis_cache_entry {
43 struct list_head node;
44 unsigned int addr;
45 unsigned int len;
46 unsigned int attr;
47 unsigned char cache[0];
48};
49
Dominik Brodowskic23889c2008-08-26 00:09:56 +020050struct pccard_resource_ops {
51 int (*validate_mem) (struct pcmcia_socket *s);
Dominik Brodowskib19a7272010-03-20 13:10:47 +010052 int (*find_io) (struct pcmcia_socket *s,
53 unsigned int attr,
54 unsigned int *base,
55 unsigned int num,
Dominik Brodowskiad0c7be2010-07-25 13:10:22 +020056 unsigned int align,
57 struct resource **parent);
Dominik Brodowskic23889c2008-08-26 00:09:56 +020058 struct resource* (*find_mem) (unsigned long base, unsigned long num,
59 unsigned long align, int low,
60 struct pcmcia_socket *s);
Dominik Brodowskic23889c2008-08-26 00:09:56 +020061 int (*init) (struct pcmcia_socket *s);
62 void (*exit) (struct pcmcia_socket *s);
63};
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065/* Flags in config state */
66#define CONFIG_LOCKED 0x01
67#define CONFIG_IRQ_REQ 0x02
68#define CONFIG_IO_REQ 0x04
69
70/* Flags in socket state */
71#define SOCKET_PRESENT 0x0008
72#define SOCKET_INUSE 0x0010
Rafael J. Wysockidbdd0f52018-02-21 13:24:16 +010073#define SOCKET_IN_RESUME 0x0040
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#define SOCKET_SUSPEND 0x0080
75#define SOCKET_WIN_REQ(i) (0x0100<<(i))
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#define SOCKET_CARDBUS 0x8000
77#define SOCKET_CARDBUS_CONFIG 0x10000
78
Dominik Brodowskidc953e52008-08-25 23:18:20 +020079
80/*
Dominik Brodowski49b11532010-03-07 16:41:57 +010081 * Stuff internal to module "pcmcia_rsrc":
82 */
83extern int static_init(struct pcmcia_socket *s);
Alan Coxa6c61932014-12-10 15:05:38 +000084extern struct resource *pcmcia_make_resource(resource_size_t start,
85 resource_size_t end,
86 unsigned long flags, const char *name);
Dominik Brodowski49b11532010-03-07 16:41:57 +010087
88/*
Dominik Brodowskidc953e52008-08-25 23:18:20 +020089 * Stuff internal to module "pcmcia_core":
90 */
91
Dominik Brodowskidc953e52008-08-25 23:18:20 +020092/* socket_sysfs.c */
93extern int pccard_sysfs_add_socket(struct device *dev);
94extern void pccard_sysfs_remove_socket(struct device *dev);
95
96/* cardbus.c */
97int cb_alloc(struct pcmcia_socket *s);
98void cb_free(struct pcmcia_socket *s);
Dominik Brodowskidc953e52008-08-25 23:18:20 +020099
100
101
102/*
103 * Stuff exported by module "pcmcia_core" to module "pcmcia"
104 */
105
106struct pcmcia_callback{
107 struct module *owner;
Dominik Brodowski7b24e792010-07-11 10:26:53 +0200108 int (*add) (struct pcmcia_socket *s);
109 int (*remove) (struct pcmcia_socket *s);
Dominik Brodowskiaf461fc2010-01-17 19:30:53 +0100110 void (*requery) (struct pcmcia_socket *s);
Dominik Brodowski6e7b51a2010-01-06 13:57:43 +0100111 int (*validate) (struct pcmcia_socket *s, unsigned int *i);
Dominik Brodowskidc953e52008-08-25 23:18:20 +0200112 int (*suspend) (struct pcmcia_socket *s);
Dominik Brodowski7b24e792010-07-11 10:26:53 +0200113 int (*early_resume) (struct pcmcia_socket *s);
Dominik Brodowskidc953e52008-08-25 23:18:20 +0200114 int (*resume) (struct pcmcia_socket *s);
115};
116
117/* cs.c */
118extern struct rw_semaphore pcmcia_socket_list_rwsem;
119extern struct list_head pcmcia_socket_list;
Dominik Brodowskic23889c2008-08-26 00:09:56 +0200120extern struct class pcmcia_socket_class;
121
Dominik Brodowskidc953e52008-08-25 23:18:20 +0200122int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
Dominik Brodowskic23889c2008-08-26 00:09:56 +0200123struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr);
Dominik Brodowskidc953e52008-08-25 23:18:20 +0200124
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100125void pcmcia_parse_uevents(struct pcmcia_socket *socket, unsigned int events);
126#define PCMCIA_UEVENT_EJECT 0x0001
127#define PCMCIA_UEVENT_INSERT 0x0002
128#define PCMCIA_UEVENT_SUSPEND 0x0004
129#define PCMCIA_UEVENT_RESUME 0x0008
Dominik Brodowskiaf461fc2010-01-17 19:30:53 +0100130#define PCMCIA_UEVENT_REQUERY 0x0010
Dominik Brodowski994917f2008-08-31 15:20:26 +0200131
132struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt);
133void pcmcia_put_socket(struct pcmcia_socket *skt);
134
Dominik Brodowskib60a5ed2008-08-25 23:32:37 +0200135/*
136 * Stuff internal to module "pcmcia".
137 */
138/* ds.c */
139extern struct bus_type pcmcia_bus_type;
140
Dominik Brodowski5716d412010-07-11 09:51:14 +0200141struct pcmcia_device;
142
Dominik Brodowskib60a5ed2008-08-25 23:32:37 +0200143/* pcmcia_resource.c */
144extern int pcmcia_release_configuration(struct pcmcia_device *p_dev);
Dominik Brodowskia3ac9af2010-01-06 14:03:03 +0100145extern int pcmcia_validate_mem(struct pcmcia_socket *s);
146extern 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
Dominik Brodowski6f0f38c2010-04-08 20:33:16 +0200152void pcmcia_cleanup_irq(struct pcmcia_socket *s);
153int pcmcia_setup_irq(struct pcmcia_device *p_dev);
Dominik Brodowskib60a5ed2008-08-25 23:32:37 +0200154
Dominik Brodowski6e7b51a2010-01-06 13:57:43 +0100155/* cistpl.c */
Bhumika Goyalc1512062017-09-30 22:29:54 +0530156extern const struct bin_attribute pccard_cis_attr;
Dominik Brodowski6e7b51a2010-01-06 13:57:43 +0100157
158int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr,
159 u_int addr, u_int len, void *ptr);
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200160int pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr,
161 u_int addr, u_int len, void *ptr);
Dominik Brodowski6e7b51a2010-01-06 13:57:43 +0100162void release_cis_mem(struct pcmcia_socket *s);
163void destroy_cis_cache(struct pcmcia_socket *s);
164int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function,
165 cisdata_t code, void *parse);
166int pcmcia_replace_cis(struct pcmcia_socket *s,
167 const u8 *data, const size_t len);
168int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *count);
169int verify_cis_cache(struct pcmcia_socket *s);
170
171int 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
177int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function,
178 tuple_t *tuple);
179
180int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function,
181 tuple_t *tuple);
182
183int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple);
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185#endif /* _LINUX_CS_INTERNAL_H */