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