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
|
167/* More later? */ 168struct pccard_ivar { 169 struct resource_list resources; 170 int slotnum; 171}; 172 173struct pccard_softc { 174 device_t dev; 175 /* this stuff is for the socket */ 176 177 /* this stuff is for the card */ 178 struct pccard_card card; 179 void *ih; 180 int sc_enabled_count; /* num functions enabled */ 181 182}; 183 184void 185pccardbus_if_setup(struct pccard_softc*); 186 187struct pccard_cis_quirk { 188 int32_t manufacturer; 189 int32_t product; 190 char *cis1_info[4]; 191 struct pccard_function *pf; 192 struct pccard_config_entry *cfe; 193}; 194 195struct pccard_tuple { 196 unsigned int code; 197 unsigned int length; 198 u_long mult; 199 bus_addr_t ptr; 200 bus_space_tag_t memt; 201 bus_space_handle_t memh; 202}; 203 204void pccard_read_cis(struct pccard_softc *); 205void pccard_check_cis_quirks(device_t); 206void pccard_print_cis(device_t); 207int pccard_scan_cis(device_t, 208 int (*) (struct pccard_tuple *, void *), void *); 209 210#define pccard_cis_read_1(tuple, idx0) \ 211 (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0))) 212 213#define pccard_tuple_read_1(tuple, idx1) \ 214 (pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1))))) 215 216#define pccard_tuple_read_2(tuple, idx2) \ 217 (pccard_tuple_read_1((tuple), (idx2)) | \ 218 (pccard_tuple_read_1((tuple), (idx2)+1)<<8)) 219 220#define pccard_tuple_read_3(tuple, idx3) \ 221 (pccard_tuple_read_1((tuple), (idx3)) | \ 222 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) | \ 223 (pccard_tuple_read_1((tuple), (idx3)+2)<<16)) 224 225#define pccard_tuple_read_4(tuple, idx4) \ 226 (pccard_tuple_read_1((tuple), (idx4)) | \ 227 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) | \ 228 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) | \ 229 (pccard_tuple_read_1((tuple), (idx4)+3)<<24)) 230 231#define pccard_tuple_read_n(tuple, n, idxn) \ 232 (((n)==1)?pccard_tuple_read_1((tuple), (idxn)) : \ 233 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) : \ 234 (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) : \ 235 /* n == 4 */ pccard_tuple_read_4((tuple), (idxn))))) 236 237#define PCCARD_SPACE_MEMORY 1 238#define PCCARD_SPACE_IO 2 239 240int pccard_ccr_read(struct pccard_function *, int); 241void pccard_ccr_write(struct pccard_function *, int, int); 242 243#define pccard_mfc(sc) (STAILQ_FIRST(&(sc)->card.pf_head) && \ 244 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list)) 245 246void pccard_function_init(struct pccard_function *, 247 struct pccard_config_entry *); 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 265#define pccard_mem_free(pf, pcmhp) \ 266 (pccard_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp))) 267 268#define pccard_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \ 269 (pccard_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind), \ 270 (card_addr), (size), (pcmhp), (offsetp), (windowp))) 271 272#define pccard_mem_unmap(pf, window) \ 273 (pccard_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window))) 274 275/* ivar interface */ 276enum { 277 PCCARD_IVAR_ETHADDR, /* read ethernet address from CIS tupple */ 278}; 279 280/* read ethernet address from CIS tupple */ 281__inline static int 282pccard_get_ether(device_t dev, u_char *enaddr) 283{ 284 return BUS_READ_IVAR(device_get_parent(dev), dev, 285 PCCARD_IVAR_ETHADDR, (uintptr_t *)enaddr); 286} 287 288enum { 289 PCCARD_A_MEM_ATTR = 0x1 290}; 291
|