pccardvar.h revision 66058
1/* $NetBSD: pcmciavar.h,v 1.9 1998/12/29 09:00:28 marc Exp $ */ 2/* $FreeBSD: head/sys/dev/pccard/pccardvar.h 66058 2000-09-19 04:39:20Z imp $ */ 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; 64 int kind; 65}; 66 67/* pccard itself */ 68 69#define PCCARD_CFE_MWAIT_REQUIRED 0x0001 70#define PCCARD_CFE_RDYBSY_ACTIVE 0x0002 71#define PCCARD_CFE_WP_ACTIVE 0x0004 72#define PCCARD_CFE_BVD_ACTIVE 0x0008 73#define PCCARD_CFE_IO8 0x0010 74#define PCCARD_CFE_IO16 0x0020 75#define PCCARD_CFE_IRQSHARE 0x0040 76#define PCCARD_CFE_IRQPULSE 0x0080 77#define PCCARD_CFE_IRQLEVEL 0x0100 78#define PCCARD_CFE_POWERDOWN 0x0200 79#define PCCARD_CFE_READONLY 0x0400 80#define PCCARD_CFE_AUDIO 0x0800 81 82struct pccard_config_entry { 83 int number; 84 u_int32_t flags; 85 int iftype; 86 int num_iospace; 87 88 /* 89 * The card will only decode this mask in any case, so we can 90 * do dynamic allocation with this in mind, in case the suggestions 91 * below are no good. 92 */ 93 u_long iomask; 94 struct { 95 u_long length; 96 u_long start; 97 } iospace[4]; /* XXX this could be as high as 16 */ 98 u_int16_t irqmask; 99 int num_memspace; 100 struct { 101 u_long length; 102 u_long cardaddr; 103 u_long hostaddr; 104 } memspace[2]; /* XXX this could be as high as 8 */ 105 int maxtwins; 106 STAILQ_ENTRY(pccard_config_entry) cfe_list; 107}; 108 109struct pccard_function { 110 /* read off the card */ 111 int number; 112 int function; 113 int last_config_index; 114 u_long ccr_base; 115 u_long ccr_mask; 116 struct resource *ccr_res; 117 int ccr_rid; 118 STAILQ_HEAD(, pccard_config_entry) cfe_head; 119 STAILQ_ENTRY(pccard_function) pf_list; 120 /* run-time state */ 121 struct pccard_softc *sc; 122 struct pccard_config_entry *cfe; 123 struct pccard_mem_handle pf_pcmh; 124 device_t dev; 125#define pf_ccrt pf_pcmh.memt 126#define pf_ccrh pf_pcmh.memh 127#define pf_ccr_realsize pf_pcmh.realsize 128 bus_addr_t pf_ccr_offset; 129 int pf_ccr_window; 130 long pf_mfc_iobase; 131 long pf_mfc_iomax; 132 int (*ih_fct)(void *); 133 void *ih_arg; 134 int ih_ipl; 135 int pf_flags; 136}; 137 138/* pf_flags */ 139#define PFF_ENABLED 0x0001 /* function is enabled */ 140 141struct pccard_card { 142 int cis1_major; 143 int cis1_minor; 144 /* XXX waste of space? */ 145 char cis1_info_buf[256]; 146 char *cis1_info[4]; 147 /* 148 * Use int32_t for manufacturer and product so that they can 149 * hold the id value found in card CIS and special value that 150 * indicates no id was found. 151 */ 152 int32_t manufacturer; 153#define PCCARD_VENDOR_INVALID -1 154 int32_t product; 155#define PCCARD_PRODUCT_INVALID -1 156 u_int16_t error; 157#define PCCARD_CIS_INVALID { NULL, NULL, NULL, NULL } 158 STAILQ_HEAD(, pccard_function) pf_head; 159}; 160 161#define PCCARD_MEM_ATTR 1 162#define PCCARD_MEM_COMMON 2 163 164#define PCCARD_WIDTH_AUTO 0 165#define PCCARD_WIDTH_IO8 1 166#define PCCARD_WIDTH_IO16 2 167 168/* More later? */ 169struct pccard_ivar { 170 struct resource_list resources; 171 struct pccard_function *fcn; 172}; 173 174struct pccard_softc { 175 device_t dev; 176 /* this stuff is for the socket */ 177 178 /* this stuff is for the card */ 179 struct pccard_card card; 180 int sc_enabled_count; /* num functions enabled */ 181}; 182 183void 184pccardbus_if_setup(struct pccard_softc*); 185 186struct pccard_cis_quirk { 187 int32_t manufacturer; 188 int32_t product; 189 char *cis1_info[4]; 190 struct pccard_function *pf; 191 struct pccard_config_entry *cfe; 192}; 193 194struct pccard_tuple { 195 unsigned int code; 196 unsigned int length; 197 u_long mult; 198 bus_addr_t ptr; 199 bus_space_tag_t memt; 200 bus_space_handle_t memh; 201}; 202 203void pccard_read_cis(struct pccard_softc *); 204void pccard_check_cis_quirks(device_t); 205void pccard_print_cis(device_t); 206int pccard_scan_cis(device_t, 207 int (*) (struct pccard_tuple *, void *), void *); 208 209#define pccard_cis_read_1(tuple, idx0) \ 210 (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0))) 211 212#define pccard_tuple_read_1(tuple, idx1) \ 213 (pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1))))) 214 215#define pccard_tuple_read_2(tuple, idx2) \ 216 (pccard_tuple_read_1((tuple), (idx2)) | \ 217 (pccard_tuple_read_1((tuple), (idx2)+1)<<8)) 218 219#define pccard_tuple_read_3(tuple, idx3) \ 220 (pccard_tuple_read_1((tuple), (idx3)) | \ 221 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) | \ 222 (pccard_tuple_read_1((tuple), (idx3)+2)<<16)) 223 224#define pccard_tuple_read_4(tuple, idx4) \ 225 (pccard_tuple_read_1((tuple), (idx4)) | \ 226 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) | \ 227 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) | \ 228 (pccard_tuple_read_1((tuple), (idx4)+3)<<24)) 229 230#define pccard_tuple_read_n(tuple, n, idxn) \ 231 (((n)==1)?pccard_tuple_read_1((tuple), (idxn)) : \ 232 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) : \ 233 (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) : \ 234 /* n == 4 */ pccard_tuple_read_4((tuple), (idxn))))) 235 236#define PCCARD_SPACE_MEMORY 1 237#define PCCARD_SPACE_IO 2 238 239int pccard_ccr_read(struct pccard_function *, int); 240void pccard_ccr_write(struct pccard_function *, int, int); 241 242#define pccard_mfc(sc) (STAILQ_FIRST(&(sc)->card.pf_head) && \ 243 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list)) 244 245/* The following is the vestages of the NetBSD driver api */ 246 247void pccard_function_init(struct pccard_function *); 248int pccard_function_enable(struct pccard_function *); 249void pccard_function_disable(struct pccard_function *); 250 251#define pccard_io_alloc(pf, start, size, align, pciop) \ 252 (pccard_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start), \ 253 (size), (align), (pciop))) 254 255#define pccard_io_free(pf, pciohp) \ 256 (pccard_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp))) 257 258int pccard_io_map(struct pccard_function *, int, bus_addr_t, 259 bus_size_t, struct pccard_io_handle *, int *); 260void pccard_io_unmap(struct pccard_function *, int); 261 262#define pccard_mem_alloc(pf, size, pcmhp) \ 263 (pccard_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp))) 264#define pccard_mem_free(pf, pcmhp) \ 265 (pccard_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp))) 266#define pccard_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \ 267 (pccard_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind), \ 268 (card_addr), (size), (pcmhp), (offsetp), (windowp))) 269#define pccard_mem_unmap(pf, window) \ 270 (pccard_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window))) 271 272/* compat layer */ 273int pccard_compat_probe(device_t dev); 274int pccard_compat_attach(device_t dev); 275 276/* ivar interface */ 277enum { 278 PCCARD_IVAR_ETHADDR, /* read ethernet address from CIS tupple */ 279}; 280 281/* read ethernet address from CIS tupple */ 282__inline static int 283pccard_get_ether(device_t dev, u_char *enaddr) 284{ 285 return BUS_READ_IVAR(device_get_parent(dev), dev, 286 PCCARD_IVAR_ETHADDR, (uintptr_t *)enaddr); 287} 288 289enum { 290 PCCARD_A_MEM_ATTR = 0x1 291}; 292 293#define PCCARD_SOFTC(d) (struct pccard_softc *) device_get_softc(d) 294