]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/pccard/pccardvar.h
Expand cryptic comment with inforation I've learned in the mean time
[FreeBSD/FreeBSD.git] / sys / dev / pccard / pccardvar.h
1 /*      $NetBSD: pcmciavar.h,v 1.12 2000/02/08 12:51:31 enami Exp $     */
2 /* $FreeBSD$ */
3
4 /*-
5  * SPDX-License-Identifier: BSD-4-Clause
6  *
7  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed by Marc Horowitz.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 /*
36  * Contains information about mapped/allocated i/o spaces.
37  */
38 struct pccard_io_handle {
39         bus_space_tag_t iot;            /* bus space tag (from chipset) */
40         bus_space_handle_t ioh;         /* mapped space handle */
41         bus_addr_t      addr;           /* resulting address in bus space */
42         bus_size_t      size;           /* size of i/o space */
43         int             flags;          /* misc. information */
44         int             width;
45 };
46
47 #define PCCARD_IO_ALLOCATED     0x01    /* i/o space was allocated */
48
49 /*
50  * Contains information about allocated memory space.
51  */
52 struct pccard_mem_handle {
53         bus_space_tag_t memt;           /* bus space tag (from chipset) */
54         bus_space_handle_t memh;        /* mapped space handle */
55         bus_addr_t      addr;           /* resulting address in bus space */
56         bus_size_t      size;           /* size of mem space */
57         bus_size_t      realsize;       /* how much we really allocated */
58         bus_addr_t      cardaddr;       /* Absolute address on card */
59         int             kind;
60 };
61
62 /* Bits for kind */
63 #define PCCARD_MEM_16BIT        1       /* 1 -> 16bit 0 -> 8bit */
64 #define PCCARD_MEM_ATTR         2       /* 1 -> attribute mem 0 -> common */
65
66 #define PCCARD_WIDTH_AUTO       0
67 #define PCCARD_WIDTH_IO8        1
68 #define PCCARD_WIDTH_IO16       2
69
70 struct pccard_tuple {
71         unsigned int    code;
72         unsigned int    length;
73         u_long          mult;           /* dist btn successive bytes */
74         bus_addr_t      ptr;
75         bus_space_tag_t memt;
76         bus_space_handle_t memh;
77 };
78
79 typedef int (*pccard_scan_t)(const struct pccard_tuple *, void *);
80
81 struct pccard_product {
82         const char      *pp_name;
83 #define PCCARD_VENDOR_ANY (0xffffffff)
84         uint32_t        pp_vendor;              /* 0 == end of table */
85 #define PCCARD_PRODUCT_ANY (0xffffffff)
86         uint32_t        pp_product;
87         const char      *pp_cis[4];
88 };
89
90 /**
91  * Note: There's no cis3 or cis4 reported for NOMATCH / pnpinfo events for
92  * pccard It's unclear if we actually need that for automatic loading or
93  * not. These stirngs are informative, according to the standard. Some Linux
94  * drivers match on them, for example. However, FreeBSD's hardware probing is a
95  * little different than Linux so it turns out we don't need them. Some cards
96  * use CIS3 or CIS4 for a textual representation of the MAC address. In short,
97  * they aren't needed even though our friends in Linux have them. It is my
98  * belief that all the entries in Linux don't actually need to be separate there
99  * either, but it's hard to eliminate them and retest on old, possibly rare,
100  * hardware so they persist. Despite years of collecting ~300 different PC Cards
101  * off E-Bay, I've not been able to find any that need CIS3/CIS4 to select which
102  * device attaches.
103  */
104 #define PCCARD_PNP_DESCR "D:#;V32:manufacturer;V32:product;Z:cisvendor;Z:cisproduct;"
105 #define PCCARD_PNP_INFO(t) \
106         MODULE_PNP_INFO(PCCARD_PNP_DESCR, pccard, t, t, sizeof(t[0]), sizeof(t) / sizeof(t[0]) - 1); \
107
108 typedef int (*pccard_product_match_fn) (device_t dev,
109     const struct pccard_product *ent, int vpfmatch);
110
111 #include "card_if.h"
112
113 /*
114  * make this inline so that we don't have to worry about dangling references
115  * to it in the modules or the code.
116  */
117 static inline const struct pccard_product *
118 pccard_product_lookup(device_t dev, const struct pccard_product *tab,
119     size_t ent_size, pccard_product_match_fn matchfn)
120 {
121         return CARD_DO_PRODUCT_LOOKUP(device_get_parent(dev), dev,
122             tab, ent_size, matchfn);
123 }
124
125 #define pccard_cis_read_1(tuple, idx0)                                  \
126         (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
127
128 #define pccard_tuple_read_1(tuple, idx1)                                \
129         (pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
130
131 #define pccard_tuple_read_2(tuple, idx2)                                \
132         (pccard_tuple_read_1((tuple), (idx2)) |                         \
133          (pccard_tuple_read_1((tuple), (idx2)+1)<<8))
134
135 #define pccard_tuple_read_3(tuple, idx3)                                \
136         (pccard_tuple_read_1((tuple), (idx3)) |                         \
137          (pccard_tuple_read_1((tuple), (idx3)+1)<<8) |                  \
138          (pccard_tuple_read_1((tuple), (idx3)+2)<<16))
139
140 #define pccard_tuple_read_4(tuple, idx4)                                \
141         (pccard_tuple_read_1((tuple), (idx4)) |                         \
142          (pccard_tuple_read_1((tuple), (idx4)+1)<<8) |                  \
143          (pccard_tuple_read_1((tuple), (idx4)+2)<<16) |                 \
144          (pccard_tuple_read_1((tuple), (idx4)+3)<<24))
145
146 #define pccard_tuple_read_n(tuple, n, idxn)                             \
147         (((n)==1)?pccard_tuple_read_1((tuple), (idxn)) :                \
148          (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) :               \
149           (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) :              \
150            /* n == 4 */ pccard_tuple_read_4((tuple), (idxn)))))
151
152 #define PCCARD_SPACE_MEMORY     1
153 #define PCCARD_SPACE_IO         2
154
155 #define pccard_mfc(sc)                                                  \
156                 (STAILQ_FIRST(&(sc)->card.pf_head) &&                   \
157                  STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list))
158
159 /* Convenience functions */
160
161 static inline int
162 pccard_cis_scan(device_t dev, pccard_scan_t fct, void *arg)
163 {
164         return (CARD_CIS_SCAN(device_get_parent(dev), dev, fct, arg));
165 }
166
167 static inline int
168 pccard_attr_read_1(device_t dev, uint32_t offset, uint8_t *val)
169 {
170         return (CARD_ATTR_READ(device_get_parent(dev), dev, offset, val));
171 }
172
173 static inline int
174 pccard_attr_write_1(device_t dev, uint32_t offset, uint8_t val)
175 {
176         return (CARD_ATTR_WRITE(device_get_parent(dev), dev, offset, val));
177 }
178
179 static inline int
180 pccard_ccr_read_1(device_t dev, uint32_t offset, uint8_t *val)
181 {
182         return (CARD_CCR_READ(device_get_parent(dev), dev, offset, val));
183 }
184
185 static inline int
186 pccard_ccr_write_1(device_t dev, uint32_t offset, uint8_t val)
187 {
188         return (CARD_CCR_WRITE(device_get_parent(dev), dev, offset, val));
189 }
190
191 /* Hack */
192 int pccard_select_cfe(device_t dev, int entry);
193
194 /* ivar interface */
195 enum {
196         PCCARD_IVAR_ETHADDR,    /* read ethernet address from CIS tupple */
197         PCCARD_IVAR_VENDOR,
198         PCCARD_IVAR_PRODUCT,
199         PCCARD_IVAR_PRODEXT,
200         PCCARD_IVAR_FUNCTION_NUMBER,
201         PCCARD_IVAR_VENDOR_STR, /* CIS string for "Manufacturer" */
202         PCCARD_IVAR_PRODUCT_STR,/* CIS string for "Product" */
203         PCCARD_IVAR_CIS3_STR,
204         PCCARD_IVAR_CIS4_STR,
205         PCCARD_IVAR_FUNCTION,
206         PCCARD_IVAR_FUNCE_DISK
207 };
208
209 #define PCCARD_ACCESSOR(A, B, T)                                        \
210 static inline int                                                       \
211 pccard_get_ ## A(device_t dev, T *t)                                    \
212 {                                                                       \
213         return BUS_READ_IVAR(device_get_parent(dev), dev,               \
214             PCCARD_IVAR_ ## B, (uintptr_t *) t);                        \
215 }
216
217 PCCARD_ACCESSOR(ether,          ETHADDR,                uint8_t)
218 PCCARD_ACCESSOR(vendor,         VENDOR,                 uint32_t)
219 PCCARD_ACCESSOR(product,        PRODUCT,                uint32_t)
220 PCCARD_ACCESSOR(prodext,        PRODEXT,                uint16_t)
221 PCCARD_ACCESSOR(function_number,FUNCTION_NUMBER,        uint32_t)
222 PCCARD_ACCESSOR(function,       FUNCTION,               uint32_t)
223 PCCARD_ACCESSOR(funce_disk,     FUNCE_DISK,             uint16_t)
224 PCCARD_ACCESSOR(vendor_str,     VENDOR_STR,             const char *)
225 PCCARD_ACCESSOR(product_str,    PRODUCT_STR,            const char *)
226 PCCARD_ACCESSOR(cis3_str,       CIS3_STR,               const char *)
227 PCCARD_ACCESSOR(cis4_str,       CIS4_STR,               const char *)
228
229 /* shared memory flags */
230 enum {
231         PCCARD_A_MEM_COM,       /* common */
232         PCCARD_A_MEM_ATTR,      /* attribute */
233         PCCARD_A_MEM_8BIT,      /* 8 bit */
234         PCCARD_A_MEM_16BIT      /* 16 bit */
235 };
236
237 #define PCCARD_S(a, b) PCMCIA_STR_ ## a ## _ ## b
238 #define PCCARD_P(a, b) PCMCIA_PRODUCT_ ## a ## _ ## b
239 #define PCCARD_C(a, b) PCMCIA_CIS_ ## a ## _ ## b
240 #define PCMCIA_CARD_D(v, p) { PCCARD_S(v, p), PCMCIA_VENDOR_ ## v, \
241                 PCCARD_P(v, p), PCCARD_C(v, p) }
242 #define PCMCIA_CARD(v, p) { PCCARD_S(v, p), PCMCIA_VENDOR_ ## v, \
243                 PCCARD_P(v, p), PCCARD_C(v, p) }
244
245 /*
246  * Defines to decode the get_funce_disk return value.  See the PCMCIA standard
247  * for all the details of what these bits mean.
248  */
249 #define PFD_I_V_MASK            0x3
250 #define PFD_I_V_NONE_REQUIRED   0x0
251 #define PFD_I_V_REQ_MOD_ACC     0x1
252 #define PFD_I_V_REQ_ACC         0x2
253 #define PFD_I_V_REQ_ALWYS       0x1
254 #define PFD_I_S                 0x4     /* 0 rotating, 1 silicon */
255 #define PFD_I_U                 0x8     /* SN Uniq? */
256 #define PFD_I_D                 0x10    /* 0 - 1 drive, 1 - 2 drives */
257 #define PFD_P_P0                0x100
258 #define PFD_P_P1                0x200
259 #define PFD_P_P2                0x400
260 #define PFD_P_P3                0x800
261 #define PFD_P_N                 0x1000  /* 3f7/377 excluded? */
262 #define PFD_P_E                 0x2000  /* Index bit supported? */
263 #define PFD_P_I                 0x4000  /* twincard */