3 4/* 5 * Copyright (c) 1997 Marc Horowitz. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Marc Horowitz. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/types.h> 34#include <sys/queue.h> 35 36#include <machine/bus.h> 37 38extern int pccard_verbose; 39 40/* 41 * Contains information about mapped/allocated i/o spaces. 42 */ 43struct pccard_io_handle { 44 bus_space_tag_t iot; /* bus space tag (from chipset) */ 45 bus_space_handle_t ioh; /* mapped space handle */ 46 bus_addr_t addr; /* resulting address in bus space */ 47 bus_size_t size; /* size of i/o space */ 48 int flags; /* misc. information */ 49 int width; 50}; 51 52#define PCCARD_IO_ALLOCATED 0x01 /* i/o space was allocated */ 53 54/* 55 * Contains information about allocated memory space. 56 */ 57struct pccard_mem_handle { 58 bus_space_tag_t memt; /* bus space tag (from chipset) */ 59 bus_space_handle_t memh; /* mapped space handle */ 60 bus_addr_t addr; /* resulting address in bus space */ 61 bus_size_t size; /* size of mem space */ 62 bus_size_t realsize; /* how much we really allocated */ 63 long offset; /* mapped Offset on card */ 64 bus_addr_t cardaddr; /* Absolute address on card */ 65 int kind; 66}; 67 68/* pccard itself */ 69 70#define PCCARD_CFE_MWAIT_REQUIRED 0x0001 71#define PCCARD_CFE_RDYBSY_ACTIVE 0x0002 72#define PCCARD_CFE_WP_ACTIVE 0x0004 73#define PCCARD_CFE_BVD_ACTIVE 0x0008 74#define PCCARD_CFE_IO8 0x0010 75#define PCCARD_CFE_IO16 0x0020 76#define PCCARD_CFE_IRQSHARE 0x0040 77#define PCCARD_CFE_IRQPULSE 0x0080 78#define PCCARD_CFE_IRQLEVEL 0x0100 79#define PCCARD_CFE_POWERDOWN 0x0200 80#define PCCARD_CFE_READONLY 0x0400 81#define PCCARD_CFE_AUDIO 0x0800 82 83struct pccard_config_entry { 84 int number; 85 uint32_t flags; 86 int iftype; 87 int num_iospace; 88 89 /* 90 * The card will only decode this mask in any case, so we can 91 * do dynamic allocation with this in mind, in case the suggestions 92 * below are no good. 93 */ 94 u_long iomask; 95 struct { 96 u_long length; 97 u_long start; 98 } iospace[4]; /* XXX this could be as high as 16 */ 99 uint16_t irqmask; 100 int num_memspace; 101 struct { 102 u_long length; 103 u_long cardaddr; 104 u_long hostaddr; 105 } memspace[2]; /* XXX this could be as high as 8 */ 106 int maxtwins; 107 struct resource *iores[4]; 108 int iorid[4]; 109 struct resource *irqres; 110 int irqrid; 111 struct resource *memres[2]; 112 int memrid[2]; 113 STAILQ_ENTRY(pccard_config_entry) cfe_list; 114}; 115 116struct pccard_funce_disk { 117 int pfd_interface; 118}; 119 120struct pccard_funce_lan { 121 int pfl_nidlen; 122 uint8_t pfl_nid[8]; 123}; 124 125union pccard_funce { 126 struct pccard_funce_disk pfv_disk; 127 struct pccard_funce_lan pfv_lan; 128}; 129 130struct pccard_function { 131 /* read off the card */ 132 int number; 133 int function; 134 int last_config_index; 135 uint32_t ccr_base; /* Offset with card's memory */ 136 uint32_t ccr_mask; 137 struct resource *ccr_res; 138 int ccr_rid; 139 STAILQ_HEAD(, pccard_config_entry) cfe_head; 140 STAILQ_ENTRY(pccard_function) pf_list; 141 /* run-time state */ 142 struct pccard_softc *sc; 143 struct pccard_config_entry *cfe; 144 struct pccard_mem_handle pf_pcmh; 145 device_t dev; 146#define pf_ccrt pf_pcmh.memt 147#define pf_ccrh pf_pcmh.memh 148#define pf_ccr_realsize pf_pcmh.realsize 149 uint32_t pf_ccr_offset; /* Offset from ccr_base of CIS */ 150 int pf_ccr_window; 151 long pf_mfc_iobase; /* Right type? */ 152 long pf_mfc_iomax; 153 int pf_flags; 154 driver_intr_t *intr_handler; 155 void *intr_handler_arg; 156 void *intr_handler_cookie; 157 158 union pccard_funce pf_funce; /* CISTPL_FUNCE */ 159#define pf_funce_disk_interface pf_funce.pfv_disk.pfd_interface 160#define pf_funce_lan_nid pf_funce.pfv_lan.pfl_nid 161#define pf_funce_lan_nidlen pf_funce.pfv_lan.pfl_nidlen 162}; 163 164/* pf_flags */ 165#define PFF_ENABLED 0x0001 /* function is enabled */ 166 167struct pccard_card { 168 int cis1_major; 169 int cis1_minor; 170 /* XXX waste of space? */ 171 char cis1_info_buf[256]; 172 char *cis1_info[4]; 173 /* 174 * Use int32_t for manufacturer and product so that they can 175 * hold the id value found in card CIS and special value that 176 * indicates no id was found. 177 */ 178 int32_t manufacturer; 179#define PCMCIA_VENDOR_INVALID -1 180 int32_t product; 181#define PCMCIA_PRODUCT_INVALID -1 182 int16_t prodext; 183 uint16_t error; 184#define PCMCIA_CIS_INVALID { NULL, NULL, NULL, NULL } 185 STAILQ_HEAD(, pccard_function) pf_head; 186}; 187 188#define PCCARD_MEM_ATTR 1 189#define PCCARD_MEM_COMMON 2 190 191#define PCCARD_WIDTH_AUTO 0 192#define PCCARD_WIDTH_IO8 1 193#define PCCARD_WIDTH_IO16 2 194 195/* More later? */ 196struct pccard_ivar { 197 struct resource_list resources; 198 struct pccard_function *fcn; 199}; 200 201struct pccard_softc { 202 device_t dev; 203 /* this stuff is for the socket */ 204 205 /* this stuff is for the card */ 206 struct pccard_card card; 207 int sc_enabled_count; /* num functions enabled */ 208}; 209 210void 211pccardbus_if_setup(struct pccard_softc*); 212 213struct pccard_cis_quirk { 214 int32_t manufacturer; 215 int32_t product; 216 char *cis1_info[4]; 217 struct pccard_function *pf; 218 struct pccard_config_entry *cfe; 219}; 220 221struct pccard_tuple { 222 unsigned int code; 223 unsigned int length; 224 u_long mult; 225 bus_addr_t ptr; 226 bus_space_tag_t memt; 227 bus_space_handle_t memh; 228}; 229 230struct pccard_product { 231 const char *pp_name; /* NULL if end of table */ 232#define PCCARD_VENDOR_ANY (0xffffffff) 233 uint32_t pp_vendor; 234#define PCCARD_PRODUCT_ANY (0xffffffff) 235 uint32_t pp_product; 236 int pp_expfunc; 237 const char *pp_cis[4]; 238}; 239 240typedef int (*pccard_product_match_fn) (device_t dev, 241 const struct pccard_product *ent, int vpfmatch); 242 243#include "card_if.h" 244 245/* 246 * make this inline so that we don't have to worry about dangling references 247 * to it in the modules or the code. 248 */ 249static __inline const struct pccard_product * 250pccard_product_lookup(device_t dev, const struct pccard_product *tab, 251 size_t ent_size, pccard_product_match_fn matchfn) 252{ 253 return CARD_DO_PRODUCT_LOOKUP(device_get_parent(dev), dev, 254 tab, ent_size, matchfn); 255} 256 257void pccard_read_cis(struct pccard_softc *); 258void pccard_check_cis_quirks(device_t); 259void pccard_print_cis(device_t); 260int pccard_scan_cis(device_t, 261 int (*) (struct pccard_tuple *, void *), void *); 262 263#define pccard_cis_read_1(tuple, idx0) \ 264 (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0))) 265 266#define pccard_tuple_read_1(tuple, idx1) \ 267 (pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1))))) 268 269#define pccard_tuple_read_2(tuple, idx2) \ 270 (pccard_tuple_read_1((tuple), (idx2)) | \ 271 (pccard_tuple_read_1((tuple), (idx2)+1)<<8)) 272 273#define pccard_tuple_read_3(tuple, idx3) \ 274 (pccard_tuple_read_1((tuple), (idx3)) | \ 275 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) | \ 276 (pccard_tuple_read_1((tuple), (idx3)+2)<<16)) 277 278#define pccard_tuple_read_4(tuple, idx4) \ 279 (pccard_tuple_read_1((tuple), (idx4)) | \ 280 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) | \ 281 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) | \ 282 (pccard_tuple_read_1((tuple), (idx4)+3)<<24)) 283 284#define pccard_tuple_read_n(tuple, n, idxn) \ 285 (((n)==1)?pccard_tuple_read_1((tuple), (idxn)) : \ 286 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) : \ 287 (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) : \ 288 /* n == 4 */ pccard_tuple_read_4((tuple), (idxn))))) 289 290#define PCCARD_SPACE_MEMORY 1 291#define PCCARD_SPACE_IO 2 292 293#define pccard_mfc(sc) (STAILQ_FIRST(&(sc)->card.pf_head) && \ 294 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list)) 295 296#define pccard_io_alloc(pf, start, size, align, pciop) \ 297 (pccard_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start), \ 298 (size), (align), (pciop))) 299 300#define pccard_io_free(pf, pciohp) \ 301 (pccard_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp))) 302 303int pccard_io_map(struct pccard_function *, int, bus_addr_t, 304 bus_size_t, struct pccard_io_handle *, int *); 305void pccard_io_unmap(struct pccard_function *, int); 306 307#define pccard_mem_alloc(pf, size, pcmhp) \ 308 (pccard_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp))) 309#define pccard_mem_free(pf, pcmhp) \ 310 (pccard_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp))) 311#define pccard_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \ 312 (pccard_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind), \ 313 (card_addr), (size), (pcmhp), (offsetp), (windowp))) 314#define pccard_mem_unmap(pf, window) \ 315 (pccard_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window))) 316 317/* compat layer */ 318static __inline int 319pccard_compat_probe(device_t dev) 320{ 321 return (CARD_COMPAT_DO_PROBE(device_get_parent(dev), dev)); 322} 323 324static __inline int 325pccard_compat_attach(device_t dev) 326{ 327 return (CARD_COMPAT_DO_ATTACH(device_get_parent(dev), dev)); 328} 329 330/* ivar interface */ 331enum { 332 PCCARD_IVAR_ETHADDR, /* read ethernet address from CIS tupple */ 333 PCCARD_IVAR_VENDOR, 334 PCCARD_IVAR_PRODUCT, 335 PCCARD_IVAR_PRODEXT, 336 PCCARD_IVAR_FUNCTION_NUMBER, 337 PCCARD_IVAR_VENDOR_STR, /* CIS string for "Manufacturer" */ 338 PCCARD_IVAR_PRODUCT_STR,/* CIS strnig for "Product" */ 339 PCCARD_IVAR_CIS3_STR, 340 PCCARD_IVAR_CIS4_STR, 341 PCCARD_IVAR_FUNCTION 342}; 343 344#define PCCARD_ACCESSOR(A, B, T) \ 345__inline static int \ 346pccard_get_ ## A(device_t dev, T *t) \ 347{ \ 348 return BUS_READ_IVAR(device_get_parent(dev), dev, \ 349 PCCARD_IVAR_ ## B, (uintptr_t *) t); \ 350} 351 352PCCARD_ACCESSOR(ether, ETHADDR, uint8_t) 353PCCARD_ACCESSOR(vendor, VENDOR, uint32_t) 354PCCARD_ACCESSOR(product, PRODUCT, uint32_t) 355PCCARD_ACCESSOR(prodext, PRODEXT, uint16_t) 356PCCARD_ACCESSOR(function_number,FUNCTION_NUMBER, uint32_t) 357PCCARD_ACCESSOR(function, FUNCTION, uint32_t) 358PCCARD_ACCESSOR(vendor_str, VENDOR_STR, char *) 359PCCARD_ACCESSOR(product_str, PRODUCT_STR, char *) 360PCCARD_ACCESSOR(cis3_str, CIS3_STR, char *) 361 362/* shared memory flags */ 363enum { 364 PCCARD_A_MEM_COM, /* common */ 365 PCCARD_A_MEM_ATTR, /* attribute */ 366 PCCARD_A_MEM_8BIT, /* 8 bit */ 367 PCCARD_A_MEM_16BIT /* 16 bit */ 368}; 369 370#define PCCARD_SOFTC(d) (struct pccard_softc *) device_get_softc(d) 371#define PCCARD_IVAR(d) (struct pccard_ivar *) device_get_ivars(d) 372 373#define PCCARD_S(a, b) PCMCIA_STR_ ## a ## _ ## b 374#define PCCARD_P(a, b) PCMCIA_PRODUCT_ ## a ## _ ## b 375#define PCCARD_C(a, b) PCMCIA_CIS_ ## a ## _ ## b
| 3 4/* 5 * Copyright (c) 1997 Marc Horowitz. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Marc Horowitz. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/types.h> 34#include <sys/queue.h> 35 36#include <machine/bus.h> 37 38extern int pccard_verbose; 39 40/* 41 * Contains information about mapped/allocated i/o spaces. 42 */ 43struct pccard_io_handle { 44 bus_space_tag_t iot; /* bus space tag (from chipset) */ 45 bus_space_handle_t ioh; /* mapped space handle */ 46 bus_addr_t addr; /* resulting address in bus space */ 47 bus_size_t size; /* size of i/o space */ 48 int flags; /* misc. information */ 49 int width; 50}; 51 52#define PCCARD_IO_ALLOCATED 0x01 /* i/o space was allocated */ 53 54/* 55 * Contains information about allocated memory space. 56 */ 57struct pccard_mem_handle { 58 bus_space_tag_t memt; /* bus space tag (from chipset) */ 59 bus_space_handle_t memh; /* mapped space handle */ 60 bus_addr_t addr; /* resulting address in bus space */ 61 bus_size_t size; /* size of mem space */ 62 bus_size_t realsize; /* how much we really allocated */ 63 long offset; /* mapped Offset on card */ 64 bus_addr_t cardaddr; /* Absolute address on card */ 65 int kind; 66}; 67 68/* pccard itself */ 69 70#define PCCARD_CFE_MWAIT_REQUIRED 0x0001 71#define PCCARD_CFE_RDYBSY_ACTIVE 0x0002 72#define PCCARD_CFE_WP_ACTIVE 0x0004 73#define PCCARD_CFE_BVD_ACTIVE 0x0008 74#define PCCARD_CFE_IO8 0x0010 75#define PCCARD_CFE_IO16 0x0020 76#define PCCARD_CFE_IRQSHARE 0x0040 77#define PCCARD_CFE_IRQPULSE 0x0080 78#define PCCARD_CFE_IRQLEVEL 0x0100 79#define PCCARD_CFE_POWERDOWN 0x0200 80#define PCCARD_CFE_READONLY 0x0400 81#define PCCARD_CFE_AUDIO 0x0800 82 83struct pccard_config_entry { 84 int number; 85 uint32_t flags; 86 int iftype; 87 int num_iospace; 88 89 /* 90 * The card will only decode this mask in any case, so we can 91 * do dynamic allocation with this in mind, in case the suggestions 92 * below are no good. 93 */ 94 u_long iomask; 95 struct { 96 u_long length; 97 u_long start; 98 } iospace[4]; /* XXX this could be as high as 16 */ 99 uint16_t irqmask; 100 int num_memspace; 101 struct { 102 u_long length; 103 u_long cardaddr; 104 u_long hostaddr; 105 } memspace[2]; /* XXX this could be as high as 8 */ 106 int maxtwins; 107 struct resource *iores[4]; 108 int iorid[4]; 109 struct resource *irqres; 110 int irqrid; 111 struct resource *memres[2]; 112 int memrid[2]; 113 STAILQ_ENTRY(pccard_config_entry) cfe_list; 114}; 115 116struct pccard_funce_disk { 117 int pfd_interface; 118}; 119 120struct pccard_funce_lan { 121 int pfl_nidlen; 122 uint8_t pfl_nid[8]; 123}; 124 125union pccard_funce { 126 struct pccard_funce_disk pfv_disk; 127 struct pccard_funce_lan pfv_lan; 128}; 129 130struct pccard_function { 131 /* read off the card */ 132 int number; 133 int function; 134 int last_config_index; 135 uint32_t ccr_base; /* Offset with card's memory */ 136 uint32_t ccr_mask; 137 struct resource *ccr_res; 138 int ccr_rid; 139 STAILQ_HEAD(, pccard_config_entry) cfe_head; 140 STAILQ_ENTRY(pccard_function) pf_list; 141 /* run-time state */ 142 struct pccard_softc *sc; 143 struct pccard_config_entry *cfe; 144 struct pccard_mem_handle pf_pcmh; 145 device_t dev; 146#define pf_ccrt pf_pcmh.memt 147#define pf_ccrh pf_pcmh.memh 148#define pf_ccr_realsize pf_pcmh.realsize 149 uint32_t pf_ccr_offset; /* Offset from ccr_base of CIS */ 150 int pf_ccr_window; 151 long pf_mfc_iobase; /* Right type? */ 152 long pf_mfc_iomax; 153 int pf_flags; 154 driver_intr_t *intr_handler; 155 void *intr_handler_arg; 156 void *intr_handler_cookie; 157 158 union pccard_funce pf_funce; /* CISTPL_FUNCE */ 159#define pf_funce_disk_interface pf_funce.pfv_disk.pfd_interface 160#define pf_funce_lan_nid pf_funce.pfv_lan.pfl_nid 161#define pf_funce_lan_nidlen pf_funce.pfv_lan.pfl_nidlen 162}; 163 164/* pf_flags */ 165#define PFF_ENABLED 0x0001 /* function is enabled */ 166 167struct pccard_card { 168 int cis1_major; 169 int cis1_minor; 170 /* XXX waste of space? */ 171 char cis1_info_buf[256]; 172 char *cis1_info[4]; 173 /* 174 * Use int32_t for manufacturer and product so that they can 175 * hold the id value found in card CIS and special value that 176 * indicates no id was found. 177 */ 178 int32_t manufacturer; 179#define PCMCIA_VENDOR_INVALID -1 180 int32_t product; 181#define PCMCIA_PRODUCT_INVALID -1 182 int16_t prodext; 183 uint16_t error; 184#define PCMCIA_CIS_INVALID { NULL, NULL, NULL, NULL } 185 STAILQ_HEAD(, pccard_function) pf_head; 186}; 187 188#define PCCARD_MEM_ATTR 1 189#define PCCARD_MEM_COMMON 2 190 191#define PCCARD_WIDTH_AUTO 0 192#define PCCARD_WIDTH_IO8 1 193#define PCCARD_WIDTH_IO16 2 194 195/* More later? */ 196struct pccard_ivar { 197 struct resource_list resources; 198 struct pccard_function *fcn; 199}; 200 201struct pccard_softc { 202 device_t dev; 203 /* this stuff is for the socket */ 204 205 /* this stuff is for the card */ 206 struct pccard_card card; 207 int sc_enabled_count; /* num functions enabled */ 208}; 209 210void 211pccardbus_if_setup(struct pccard_softc*); 212 213struct pccard_cis_quirk { 214 int32_t manufacturer; 215 int32_t product; 216 char *cis1_info[4]; 217 struct pccard_function *pf; 218 struct pccard_config_entry *cfe; 219}; 220 221struct pccard_tuple { 222 unsigned int code; 223 unsigned int length; 224 u_long mult; 225 bus_addr_t ptr; 226 bus_space_tag_t memt; 227 bus_space_handle_t memh; 228}; 229 230struct pccard_product { 231 const char *pp_name; /* NULL if end of table */ 232#define PCCARD_VENDOR_ANY (0xffffffff) 233 uint32_t pp_vendor; 234#define PCCARD_PRODUCT_ANY (0xffffffff) 235 uint32_t pp_product; 236 int pp_expfunc; 237 const char *pp_cis[4]; 238}; 239 240typedef int (*pccard_product_match_fn) (device_t dev, 241 const struct pccard_product *ent, int vpfmatch); 242 243#include "card_if.h" 244 245/* 246 * make this inline so that we don't have to worry about dangling references 247 * to it in the modules or the code. 248 */ 249static __inline const struct pccard_product * 250pccard_product_lookup(device_t dev, const struct pccard_product *tab, 251 size_t ent_size, pccard_product_match_fn matchfn) 252{ 253 return CARD_DO_PRODUCT_LOOKUP(device_get_parent(dev), dev, 254 tab, ent_size, matchfn); 255} 256 257void pccard_read_cis(struct pccard_softc *); 258void pccard_check_cis_quirks(device_t); 259void pccard_print_cis(device_t); 260int pccard_scan_cis(device_t, 261 int (*) (struct pccard_tuple *, void *), void *); 262 263#define pccard_cis_read_1(tuple, idx0) \ 264 (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0))) 265 266#define pccard_tuple_read_1(tuple, idx1) \ 267 (pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1))))) 268 269#define pccard_tuple_read_2(tuple, idx2) \ 270 (pccard_tuple_read_1((tuple), (idx2)) | \ 271 (pccard_tuple_read_1((tuple), (idx2)+1)<<8)) 272 273#define pccard_tuple_read_3(tuple, idx3) \ 274 (pccard_tuple_read_1((tuple), (idx3)) | \ 275 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) | \ 276 (pccard_tuple_read_1((tuple), (idx3)+2)<<16)) 277 278#define pccard_tuple_read_4(tuple, idx4) \ 279 (pccard_tuple_read_1((tuple), (idx4)) | \ 280 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) | \ 281 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) | \ 282 (pccard_tuple_read_1((tuple), (idx4)+3)<<24)) 283 284#define pccard_tuple_read_n(tuple, n, idxn) \ 285 (((n)==1)?pccard_tuple_read_1((tuple), (idxn)) : \ 286 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) : \ 287 (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) : \ 288 /* n == 4 */ pccard_tuple_read_4((tuple), (idxn))))) 289 290#define PCCARD_SPACE_MEMORY 1 291#define PCCARD_SPACE_IO 2 292 293#define pccard_mfc(sc) (STAILQ_FIRST(&(sc)->card.pf_head) && \ 294 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list)) 295 296#define pccard_io_alloc(pf, start, size, align, pciop) \ 297 (pccard_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start), \ 298 (size), (align), (pciop))) 299 300#define pccard_io_free(pf, pciohp) \ 301 (pccard_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp))) 302 303int pccard_io_map(struct pccard_function *, int, bus_addr_t, 304 bus_size_t, struct pccard_io_handle *, int *); 305void pccard_io_unmap(struct pccard_function *, int); 306 307#define pccard_mem_alloc(pf, size, pcmhp) \ 308 (pccard_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp))) 309#define pccard_mem_free(pf, pcmhp) \ 310 (pccard_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp))) 311#define pccard_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \ 312 (pccard_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind), \ 313 (card_addr), (size), (pcmhp), (offsetp), (windowp))) 314#define pccard_mem_unmap(pf, window) \ 315 (pccard_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window))) 316 317/* compat layer */ 318static __inline int 319pccard_compat_probe(device_t dev) 320{ 321 return (CARD_COMPAT_DO_PROBE(device_get_parent(dev), dev)); 322} 323 324static __inline int 325pccard_compat_attach(device_t dev) 326{ 327 return (CARD_COMPAT_DO_ATTACH(device_get_parent(dev), dev)); 328} 329 330/* ivar interface */ 331enum { 332 PCCARD_IVAR_ETHADDR, /* read ethernet address from CIS tupple */ 333 PCCARD_IVAR_VENDOR, 334 PCCARD_IVAR_PRODUCT, 335 PCCARD_IVAR_PRODEXT, 336 PCCARD_IVAR_FUNCTION_NUMBER, 337 PCCARD_IVAR_VENDOR_STR, /* CIS string for "Manufacturer" */ 338 PCCARD_IVAR_PRODUCT_STR,/* CIS strnig for "Product" */ 339 PCCARD_IVAR_CIS3_STR, 340 PCCARD_IVAR_CIS4_STR, 341 PCCARD_IVAR_FUNCTION 342}; 343 344#define PCCARD_ACCESSOR(A, B, T) \ 345__inline static int \ 346pccard_get_ ## A(device_t dev, T *t) \ 347{ \ 348 return BUS_READ_IVAR(device_get_parent(dev), dev, \ 349 PCCARD_IVAR_ ## B, (uintptr_t *) t); \ 350} 351 352PCCARD_ACCESSOR(ether, ETHADDR, uint8_t) 353PCCARD_ACCESSOR(vendor, VENDOR, uint32_t) 354PCCARD_ACCESSOR(product, PRODUCT, uint32_t) 355PCCARD_ACCESSOR(prodext, PRODEXT, uint16_t) 356PCCARD_ACCESSOR(function_number,FUNCTION_NUMBER, uint32_t) 357PCCARD_ACCESSOR(function, FUNCTION, uint32_t) 358PCCARD_ACCESSOR(vendor_str, VENDOR_STR, char *) 359PCCARD_ACCESSOR(product_str, PRODUCT_STR, char *) 360PCCARD_ACCESSOR(cis3_str, CIS3_STR, char *) 361 362/* shared memory flags */ 363enum { 364 PCCARD_A_MEM_COM, /* common */ 365 PCCARD_A_MEM_ATTR, /* attribute */ 366 PCCARD_A_MEM_8BIT, /* 8 bit */ 367 PCCARD_A_MEM_16BIT /* 16 bit */ 368}; 369 370#define PCCARD_SOFTC(d) (struct pccard_softc *) device_get_softc(d) 371#define PCCARD_IVAR(d) (struct pccard_ivar *) device_get_ivars(d) 372 373#define PCCARD_S(a, b) PCMCIA_STR_ ## a ## _ ## b 374#define PCCARD_P(a, b) PCMCIA_PRODUCT_ ## a ## _ ## b 375#define PCCARD_C(a, b) PCMCIA_CIS_ ## a ## _ ## b
|