pcmciavar.h revision 1.1.2.7 1 1.1.2.7 thorpej /* $NetBSD: pcmciavar.h,v 1.1.2.7 1997/10/16 19:42:05 thorpej Exp $ */
2 1.1.2.6 thorpej
3 1.1.2.1 marc #include <sys/types.h>
4 1.1.2.1 marc #include <sys/queue.h>
5 1.1.2.1 marc
6 1.1.2.1 marc #include <machine/bus.h>
7 1.1.2.1 marc
8 1.1.2.1 marc #include <dev/pcmcia/pcmciachip.h>
9 1.1.2.1 marc
10 1.1.2.3 thorpej /*
11 1.1.2.3 thorpej * Contains information about mapped/allocated i/o spaces.
12 1.1.2.3 thorpej */
13 1.1.2.3 thorpej struct pcmcia_io_handle {
14 1.1.2.6 thorpej bus_space_tag_t iot; /* bus space tag (from chipset) */
15 1.1.2.6 thorpej bus_space_handle_t ioh; /* mapped space handle */
16 1.1.2.6 thorpej bus_addr_t addr; /* resulting address in bus space */
17 1.1.2.6 thorpej bus_size_t size; /* size of i/o space */
18 1.1.2.6 thorpej int flags; /* misc. information */
19 1.1.2.3 thorpej };
20 1.1.2.3 thorpej
21 1.1.2.3 thorpej #define PCMCIA_IO_ALLOCATED 0x01 /* i/o space was allocated */
22 1.1.2.3 thorpej
23 1.1.2.3 thorpej /*
24 1.1.2.3 thorpej * Contains information about allocated memory space.
25 1.1.2.3 thorpej */
26 1.1.2.3 thorpej struct pcmcia_mem_handle {
27 1.1.2.6 thorpej bus_space_tag_t memt; /* bus space tag (from chipset) */
28 1.1.2.6 thorpej bus_space_handle_t memh; /* mapped space handle */
29 1.1.2.6 thorpej bus_addr_t addr; /* resulting address in bus space */
30 1.1.2.6 thorpej bus_size_t size; /* size of mem space */
31 1.1.2.6 thorpej pcmcia_mem_handle_t mhandle; /* opaque memory handle */
32 1.1.2.6 thorpej bus_size_t realsize; /* how much we really allocated */
33 1.1.2.3 thorpej };
34 1.1.2.3 thorpej
35 1.1.2.1 marc /* pcmcia itself */
36 1.1.2.1 marc
37 1.1.2.1 marc #define PCMCIA_CFE_MWAIT_REQUIRED 0x0001
38 1.1.2.1 marc #define PCMCIA_CFE_RDYBSY_ACTIVE 0x0002
39 1.1.2.1 marc #define PCMCIA_CFE_WP_ACTIVE 0x0004
40 1.1.2.1 marc #define PCMCIA_CFE_BVD_ACTIVE 0x0008
41 1.1.2.1 marc #define PCMCIA_CFE_IO8 0x0010
42 1.1.2.1 marc #define PCMCIA_CFE_IO16 0x0020
43 1.1.2.1 marc #define PCMCIA_CFE_IRQSHARE 0x0040
44 1.1.2.1 marc #define PCMCIA_CFE_IRQPULSE 0x0080
45 1.1.2.1 marc #define PCMCIA_CFE_IRQLEVEL 0x0100
46 1.1.2.1 marc #define PCMCIA_CFE_POWERDOWN 0x0200
47 1.1.2.1 marc #define PCMCIA_CFE_READONLY 0x0400
48 1.1.2.1 marc #define PCMCIA_CFE_AUDIO 0x0800
49 1.1.2.1 marc
50 1.1.2.1 marc struct pcmcia_config_entry {
51 1.1.2.6 thorpej int number;
52 1.1.2.6 thorpej u_int32_t flags;
53 1.1.2.6 thorpej int iftype;
54 1.1.2.6 thorpej int num_iospace;
55 1.1.2.6 thorpej
56 1.1.2.6 thorpej /*
57 1.1.2.6 thorpej * The card will only decode this mask in any case, so we can
58 1.1.2.6 thorpej * do dynamic allocation with this in mind, in case the suggestions
59 1.1.2.6 thorpej * below are no good.
60 1.1.2.6 thorpej */
61 1.1.2.6 thorpej u_long iomask;
62 1.1.2.6 thorpej struct {
63 1.1.2.6 thorpej u_long length;
64 1.1.2.6 thorpej u_long start;
65 1.1.2.6 thorpej } iospace[4]; /* XXX this could be as high as 16 */
66 1.1.2.6 thorpej u_int16_t irqmask;
67 1.1.2.6 thorpej int num_memspace;
68 1.1.2.6 thorpej struct {
69 1.1.2.6 thorpej u_long length;
70 1.1.2.6 thorpej u_long cardaddr;
71 1.1.2.6 thorpej u_long hostaddr;
72 1.1.2.6 thorpej } memspace[2]; /* XXX this could be as high as 8 */
73 1.1.2.6 thorpej int maxtwins;
74 1.1.2.6 thorpej SIMPLEQ_ENTRY(pcmcia_config_entry) cfe_list;
75 1.1.2.1 marc };
76 1.1.2.1 marc
77 1.1.2.1 marc struct pcmcia_function {
78 1.1.2.6 thorpej /* read off the card */
79 1.1.2.6 thorpej int number;
80 1.1.2.6 thorpej int function;
81 1.1.2.6 thorpej int last_config_index;
82 1.1.2.6 thorpej u_long ccr_base;
83 1.1.2.6 thorpej u_long ccr_mask;
84 1.1.2.6 thorpej SIMPLEQ_HEAD(, pcmcia_config_entry) cfe_head;
85 1.1.2.6 thorpej SIMPLEQ_ENTRY(pcmcia_function) pf_list;
86 1.1.2.6 thorpej /* run-time state */
87 1.1.2.6 thorpej struct pcmcia_softc *sc;
88 1.1.2.6 thorpej struct pcmcia_config_entry *cfe;
89 1.1.2.6 thorpej struct pcmcia_mem_handle pf_pcmh;
90 1.1.2.3 thorpej #define pf_ccrt pf_pcmh.memt
91 1.1.2.3 thorpej #define pf_ccrh pf_pcmh.memh
92 1.1.2.3 thorpej #define pf_ccr_mhandle pf_pcmh.mhandle
93 1.1.2.3 thorpej #define pf_ccr_realsize pf_pcmh.realsize
94 1.1.2.6 thorpej bus_addr_t pf_ccr_offset;
95 1.1.2.6 thorpej int pf_ccr_window;
96 1.1.2.6 thorpej int (*ih_fct) __P((void *));
97 1.1.2.6 thorpej void *ih_arg;
98 1.1.2.6 thorpej int ih_ipl;
99 1.1.2.6 thorpej int pf_flags;
100 1.1.2.1 marc };
101 1.1.2.1 marc
102 1.1.2.4 thorpej /* pf_flags */
103 1.1.2.4 thorpej #define PFF_ENABLED 0x0001 /* function is enabled */
104 1.1.2.4 thorpej
105 1.1.2.1 marc struct pcmcia_card {
106 1.1.2.6 thorpej int cis1_major;
107 1.1.2.6 thorpej int cis1_minor;
108 1.1.2.6 thorpej /* XXX waste of space? */
109 1.1.2.6 thorpej char cis1_info_buf[256];
110 1.1.2.6 thorpej char *cis1_info[4];
111 1.1.2.6 thorpej int manufacturer;
112 1.1.2.6 thorpej u_int16_t product;
113 1.1.2.6 thorpej u_int16_t error;
114 1.1.2.6 thorpej SIMPLEQ_HEAD(, pcmcia_function) pf_head;
115 1.1.2.1 marc };
116 1.1.2.1 marc
117 1.1.2.1 marc struct pcmcia_softc {
118 1.1.2.6 thorpej struct device dev;
119 1.1.2.6 thorpej
120 1.1.2.6 thorpej /* this stuff is for the socket */
121 1.1.2.6 thorpej pcmcia_chipset_tag_t pct;
122 1.1.2.6 thorpej pcmcia_chipset_handle_t pch;
123 1.1.2.6 thorpej
124 1.1.2.6 thorpej /* this stuff is for the card */
125 1.1.2.6 thorpej struct pcmcia_card card;
126 1.1.2.6 thorpej void *ih;
127 1.1.2.6 thorpej int sc_enabled_count; /* how many functions are
128 1.1.2.6 thorpej enabled */
129 1.1.2.7 thorpej
130 1.1.2.7 thorpej /*
131 1.1.2.7 thorpej * These are passed down from the PCMCIA chip, and exist only
132 1.1.2.7 thorpej * so that cards with Very Special address allocation needs
133 1.1.2.7 thorpej * know what range they should be dealing with.
134 1.1.2.7 thorpej */
135 1.1.2.7 thorpej bus_addr_t iobase; /* start i/o space allocation here */
136 1.1.2.7 thorpej bus_size_t iosize; /* size of the i/o space range */
137 1.1.2.1 marc };
138 1.1.2.1 marc
139 1.1.2.1 marc struct pcmcia_attach_args {
140 1.1.2.6 thorpej u_int16_t manufacturer;
141 1.1.2.6 thorpej u_int16_t product;
142 1.1.2.6 thorpej struct pcmcia_card *card;
143 1.1.2.6 thorpej struct pcmcia_function *pf;
144 1.1.2.1 marc };
145 1.1.2.1 marc
146 1.1.2.1 marc struct pcmcia_tuple {
147 1.1.2.6 thorpej unsigned int code;
148 1.1.2.6 thorpej unsigned int length;
149 1.1.2.6 thorpej u_long mult;
150 1.1.2.6 thorpej bus_addr_t ptr;
151 1.1.2.6 thorpej bus_space_tag_t memt;
152 1.1.2.6 thorpej bus_space_handle_t memh;
153 1.1.2.6 thorpej };
154 1.1.2.6 thorpej
155 1.1.2.6 thorpej void pcmcia_read_cis __P((struct pcmcia_softc *));
156 1.1.2.6 thorpej void pcmcia_print_cis __P((struct pcmcia_softc *));
157 1.1.2.6 thorpej int pcmcia_scan_cis __P((struct device * dev,
158 1.1.2.6 thorpej int (*) (struct pcmcia_tuple *, void *), void *));
159 1.1.2.6 thorpej
160 1.1.2.6 thorpej #define pcmcia_cis_read_1(tuple, idx0) \
161 1.1.2.6 thorpej (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
162 1.1.2.6 thorpej
163 1.1.2.6 thorpej #define pcmcia_tuple_read_1(tuple, idx1) \
164 1.1.2.1 marc (pcmcia_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
165 1.1.2.6 thorpej
166 1.1.2.6 thorpej #define pcmcia_tuple_read_2(tuple, idx2) \
167 1.1.2.6 thorpej (pcmcia_tuple_read_1((tuple), (idx2)) | \
168 1.1.2.1 marc (pcmcia_tuple_read_1((tuple), (idx2)+1)<<8))
169 1.1.2.6 thorpej
170 1.1.2.6 thorpej #define pcmcia_tuple_read_3(tuple, idx3) \
171 1.1.2.6 thorpej (pcmcia_tuple_read_1((tuple), (idx3)) | \
172 1.1.2.6 thorpej (pcmcia_tuple_read_1((tuple), (idx3)+1)<<8) | \
173 1.1.2.1 marc (pcmcia_tuple_read_1((tuple), (idx3)+2)<<16))
174 1.1.2.6 thorpej
175 1.1.2.6 thorpej #define pcmcia_tuple_read_4(tuple, idx4) \
176 1.1.2.6 thorpej (pcmcia_tuple_read_1((tuple), (idx4)) | \
177 1.1.2.6 thorpej (pcmcia_tuple_read_1((tuple), (idx4)+1)<<8) | \
178 1.1.2.6 thorpej (pcmcia_tuple_read_1((tuple), (idx4)+2)<<16) | \
179 1.1.2.1 marc (pcmcia_tuple_read_1((tuple), (idx4)+3)<<24))
180 1.1.2.6 thorpej
181 1.1.2.6 thorpej #define pcmcia_tuple_read_n(tuple, n, idxn) \
182 1.1.2.6 thorpej (((n)==1)?pcmcia_tuple_read_1((tuple), (idxn)) : \
183 1.1.2.6 thorpej (((n)==2)?pcmcia_tuple_read_2((tuple), (idxn)) : \
184 1.1.2.6 thorpej (((n)==3)?pcmcia_tuple_read_3((tuple), (idxn)) : \
185 1.1.2.1 marc /* n == 4 */ pcmcia_tuple_read_4((tuple), (idxn)))))
186 1.1.2.1 marc
187 1.1.2.6 thorpej #define PCMCIA_SPACE_MEMORY 1
188 1.1.2.6 thorpej #define PCMCIA_SPACE_IO 2
189 1.1.2.1 marc
190 1.1.2.6 thorpej int pcmcia_ccr_read __P((struct pcmcia_function *, int));
191 1.1.2.6 thorpej void pcmcia_ccr_write __P((struct pcmcia_function *, int, int));
192 1.1.2.1 marc
193 1.1.2.6 thorpej #define pcmcia_mfc(sc) ((sc)->card.pf_head.sqh_first && \
194 1.1.2.6 thorpej (sc)->card.pf_head.sqh_first->pf_list.sqe_next)
195 1.1.2.1 marc
196 1.1.2.6 thorpej void pcmcia_function_init __P((struct pcmcia_function *,
197 1.1.2.6 thorpej struct pcmcia_config_entry *));
198 1.1.2.6 thorpej int pcmcia_function_enable __P((struct pcmcia_function *));
199 1.1.2.6 thorpej void pcmcia_function_disable __P((struct pcmcia_function *));
200 1.1.2.1 marc
201 1.1.2.6 thorpej #define pcmcia_io_alloc(pf, start, size, align, pciop) \
202 1.1.2.6 thorpej (pcmcia_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start), \
203 1.1.2.6 thorpej (size), (align), (pciop)))
204 1.1.2.1 marc
205 1.1.2.6 thorpej int pcmcia_io_map __P((struct pcmcia_function *, int, bus_addr_t,
206 1.1.2.6 thorpej bus_size_t, struct pcmcia_io_handle *, int *));
207 1.1.2.1 marc
208 1.1.2.6 thorpej #define pcmcia_mem_alloc(pf, size, pcmhp) \
209 1.1.2.3 thorpej (pcmcia_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
210 1.1.2.6 thorpej
211 1.1.2.6 thorpej #define pcmcia_mem_free(pf, pcmhp) \
212 1.1.2.3 thorpej (pcmcia_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
213 1.1.2.6 thorpej
214 1.1.2.3 thorpej #define pcmcia_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
215 1.1.2.6 thorpej (pcmcia_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind), \
216 1.1.2.6 thorpej (card_addr), (size), (pcmhp), (offsetp), (windowp)))
217 1.1.2.6 thorpej
218 1.1.2.6 thorpej #define pcmcia_mem_unmap(pf, window) \
219 1.1.2.1 marc (pcmcia_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
220 1.1.2.1 marc
221 1.1.2.6 thorpej void *pcmcia_intr_establish __P((struct pcmcia_function *, int,
222 1.1.2.6 thorpej int (*) (void *), void *));
223 1.1.2.6 thorpej void pcmcia_intr_disestablish __P((struct pcmcia_function *, void *));
224