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