xref: /openbmc/linux/drivers/pcmcia/cs_internal.h (revision a2cce7a9)
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 - 2010	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 /* Flag to access all functions */
30 #define BIND_FN_ALL	0xff
31 
32 /* Each card function gets one of these guys */
33 typedef struct config_t {
34 	struct kref	ref;
35 	unsigned int	state;
36 
37 	struct resource io[MAX_IO_WIN]; /* io ports */
38 	struct resource mem[MAX_WIN];   /* mem areas */
39 } config_t;
40 
41 
42 struct 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 
50 struct pccard_resource_ops {
51 	int	(*validate_mem)		(struct pcmcia_socket *s);
52 	int	(*find_io)		(struct pcmcia_socket *s,
53 					 unsigned int attr,
54 					 unsigned int *base,
55 					 unsigned int num,
56 					 unsigned int align,
57 					 struct resource **parent);
58 	struct resource* (*find_mem)	(unsigned long base, unsigned long num,
59 					 unsigned long align, int low,
60 					 struct pcmcia_socket *s);
61 	int	(*init)			(struct pcmcia_socket *s);
62 	void	(*exit)			(struct pcmcia_socket *s);
63 };
64 
65 /* 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
73 #define SOCKET_SUSPEND		0x0080
74 #define SOCKET_WIN_REQ(i)	(0x0100<<(i))
75 #define SOCKET_CARDBUS		0x8000
76 #define SOCKET_CARDBUS_CONFIG	0x10000
77 
78 
79 /*
80  * Stuff internal to module "pcmcia_rsrc":
81  */
82 extern int static_init(struct pcmcia_socket *s);
83 extern struct resource *pcmcia_make_resource(resource_size_t start,
84 					resource_size_t end,
85 					unsigned long flags, const char *name);
86 
87 /*
88  * Stuff internal to module "pcmcia_core":
89  */
90 
91 /* socket_sysfs.c */
92 extern int pccard_sysfs_add_socket(struct device *dev);
93 extern void pccard_sysfs_remove_socket(struct device *dev);
94 
95 /* cardbus.c */
96 int cb_alloc(struct pcmcia_socket *s);
97 void cb_free(struct pcmcia_socket *s);
98 
99 
100 
101 /*
102  * Stuff exported by module "pcmcia_core" to module "pcmcia"
103  */
104 
105 struct pcmcia_callback{
106 	struct module	*owner;
107 	int		(*add) (struct pcmcia_socket *s);
108 	int		(*remove) (struct pcmcia_socket *s);
109 	void		(*requery) (struct pcmcia_socket *s);
110 	int		(*validate) (struct pcmcia_socket *s, unsigned int *i);
111 	int		(*suspend) (struct pcmcia_socket *s);
112 	int		(*early_resume) (struct pcmcia_socket *s);
113 	int		(*resume) (struct pcmcia_socket *s);
114 };
115 
116 /* cs.c */
117 extern struct rw_semaphore pcmcia_socket_list_rwsem;
118 extern struct list_head pcmcia_socket_list;
119 extern struct class pcmcia_socket_class;
120 
121 int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
122 struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr);
123 
124 void pcmcia_parse_uevents(struct pcmcia_socket *socket, unsigned int events);
125 #define PCMCIA_UEVENT_EJECT	0x0001
126 #define PCMCIA_UEVENT_INSERT	0x0002
127 #define PCMCIA_UEVENT_SUSPEND	0x0004
128 #define PCMCIA_UEVENT_RESUME	0x0008
129 #define PCMCIA_UEVENT_REQUERY	0x0010
130 
131 struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt);
132 void pcmcia_put_socket(struct pcmcia_socket *skt);
133 
134 /*
135  * Stuff internal to module "pcmcia".
136  */
137 /* ds.c */
138 extern struct bus_type pcmcia_bus_type;
139 
140 struct pcmcia_device;
141 
142 /* pcmcia_resource.c */
143 extern int pcmcia_release_configuration(struct pcmcia_device *p_dev);
144 extern int pcmcia_validate_mem(struct pcmcia_socket *s);
145 extern struct resource *pcmcia_find_mem_region(u_long base,
146 					       u_long num,
147 					       u_long align,
148 					       int low,
149 					       struct pcmcia_socket *s);
150 
151 void pcmcia_cleanup_irq(struct pcmcia_socket *s);
152 int pcmcia_setup_irq(struct pcmcia_device *p_dev);
153 
154 /* cistpl.c */
155 extern struct bin_attribute pccard_cis_attr;
156 
157 int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr,
158 			u_int addr, u_int len, void *ptr);
159 int pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr,
160 			u_int addr, u_int len, void *ptr);
161 void release_cis_mem(struct pcmcia_socket *s);
162 void destroy_cis_cache(struct pcmcia_socket *s);
163 int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function,
164 		      cisdata_t code, void *parse);
165 int pcmcia_replace_cis(struct pcmcia_socket *s,
166 		       const u8 *data, const size_t len);
167 int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *count);
168 int verify_cis_cache(struct pcmcia_socket *s);
169 
170 int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function,
171 		      cisdata_t code, cisparse_t *parse, void *priv_data,
172 		      int (*loop_tuple) (tuple_t *tuple,
173 					 cisparse_t *parse,
174 					 void *priv_data));
175 
176 int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function,
177 			tuple_t *tuple);
178 
179 int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function,
180 			tuple_t *tuple);
181 
182 int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple);
183 
184 #endif /* _LINUX_CS_INTERNAL_H */
185